Link to home
Start Free TrialLog in
Avatar of pcox9999
pcox9999Flag for United States of America

asked on

SetWindowPos causes taskbar button to flash

I need to make a form in an application always be the top z ordered form on a messy desktop, and explicitly set focus to an edit box in the form. When I call SetWindowPos it always brings the form to the topmost z position but the focus is set to the application's button on the taskbar which is flashing.  I need that to stop and instead have focus appear in a waiting TEdit of the form.

Is there a work around for the behavior of SetWindowPos or another technique.
SetWindowPos(Self.Handle,
               HWND_TOPMOST,
               Top,
               Left,
               Width,
               Height,
               SWP_NOMOVE + SWP_NOSIZE)

Open in new window

Avatar of Geert G
Geert G
Flag of Belgium image

in the form properties set the formstyle to fsStayOnTop (you can do this in the IDE)

procedure TForm1.Test;
begin
  Form2.ActiveControl := Form2.Edit1;
end;
Avatar of pcox9999

ASKER

That won't work.  Focus is on the taskbar button for the app.  The taskbar button is flashing.  This is the behavior of Windows SetWindowsPos.  I tried using Windows.SetForegroundWindow(Self.Handle); but that too sets the application button on the taskbar to flash.  The solution seems to be outside my app and in Windows.  BTW, I am using Delphi 2007 and Windows XP Pro.
This means your app isn't the active app, and a window in your app has changed focus or z-order

Do you want your app to remain inactive ?

if you change your app to active first and then change the z-order this flashing shouldn't happen
Doesn't help.  Maybe I'm leaving something out of my code.  Here is the FormShow method that is giving me a headache.  Note that the extra call to SetForegroundWindow makes no difference if it is in or commented out.

Thanks.


procedure TfrmPatLookup.FormShow(Sender: TObject);
begin
 
  {set the z order for all the windows forms so this
   form is the topmost}
 
  Self.ActiveControl := Self.ePatient;
 
  SetWindowPos(Self.Handle,
               HWND_TOPMOST,
               Top,
               Left,
               Width,
               Height,
               SWP_NOMOVE + SWP_NOSIZE);
 
  SetForegroundWindow(Self.Handle);
 
  if Self.ePatient.CanFocus then
    Self.epatient.SetFocus;
end;

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Geert G
Geert G
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial