View Single Post
  #3  
Old 05-18-2005, 12:34 PM
douglas douglas is offline
Senior Member
 
Join Date: Jul 2001
Posts: 7,695
Default RE: How to make external application stay on top

You can do this using the setwindowpos routine in the WinAPI

UnSYsApps

procedure TForm1.Button1Click(Sender: TObject);
var
currhwnd: HWND;
newhwnd : HWND;
counter : Integer;
begin
currhwnd:= GetForegroundWindow;
If ShellExecute( handle, Nil, 'calc.exe', Nil, Nil,
SW_SHOWNORMAL ) > 32
Then Begin
counter := 0;
Repeat
Sleep(100);
newhwnd := GetForegroundWindow;
If (newhwnd <> 0) and (newhwnd <> currhwnd) Then Begin
SetWindowPos( newhwnd, HWND_TOPMOST, 0, 0, 0, 0,
SWP_NOSIZE or SWP_NOMOVE );
counter := 20;
End
Else
Inc( counter );
Until counter >= 20;
End;
end;
Reply With Quote