function AppActivate(WindowName : PChar) : boolean;
var
myhandle: thandle;
i: byte;
begin
i:=0;
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);
end else Result:=false;
except
on Exception do Result:=false;
end;
// eigentlich sollte das hier schon reichen, aber dank Microschrott gibts ja für
// alle befehle auch ausnahmen...
delay(10);
// Kontrolle ob Window auch wirklich im Vordergrund - versuche es nochmal max.20x
while (windows.GetForegroundWindow<>windowhandle)
and (i<20)
do begin
try
if (i>15)
then begin
// wenn alles nichts hilft verkleinere zuerst alle Fenster
myhandle := WindowHandle;
while myhandle > 0
do begin
if IsWindowVisible(myhandle)
then PostMessage(myhandle, WM_SYSCOMMAND, SC_MINIMIZE, 0);
myhandle := GetNextWindow(myhandle, GW_HWNDNEXT);
end;
end;
Result:=true;
SendMessage(WindowHandle, WM_SYSCOMMAND, SC_HOTKEY, WindowHandle);
SendMessage(WindowHandle, WM_SYSCOMMAND, SC_RESTORE, WindowHandle);
windows.ShowWindow(WindowHandle, SW_ShowNormal);
windows.SetForegroundWindow(WindowHandle);
windows.SetFocus(WindowHandle);
except
on Exception do Result:=false;
end;
inc(i);
delay(10);
end;
end;