function AppActivate(const WindowName: PChar) : Boolean;
var
WindowHandle: THandle;
function EnumWindowsProc(WHandle: HWND; lParam: LPARAM): BOOL; export; stdcall;
const
MAX_WINDOW_NAME_LEN = 80;
var
WindowName: array[0..MAX_WINDOW_NAME_LEN] of char;
begin
{Can't test GetWindowText's return value since some windows don't have a title}
GetWindowText(WHandle, WindowName, MAX_WINDOW_NAME_LEN);
Result := (StrLIComp(WindowName, PChar(lParam), StrLen(PChar(lParam))) <> 0);
if (not Result) then WindowHandle := WHandle;
end;
begin
try
Result := True;
WindowHandle := FindWindow(nil, WindowName);
if (WindowHandle = 0) then EnumWindows(@EnumWindowsProc, Integer(PChar(WindowName)));
if (WindowHandle <> 0) then begin
SendMessage(WindowHandle, WM_SYSCOMMAND, SC_HOTKEY, WindowHandle);
SendMessage(WindowHandle, WM_SYSCOMMAND, SC_RESTORE, WindowHandle);
Sleep(100);
end else Result := False;
except
on
Exception do Result := False;
end;
end;