Solved

SetWindowPos causes taskbar button to flash

Posted on 2009-07-10
5
881 Views
Last Modified: 2012-06-27
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

0
Comment
Question by:pcox9999
  • 3
  • 2
5 Comments
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 24826952
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;
0
 

Author Comment

by:pcox9999
ID: 24827004
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.
0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 24827032
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
0
 

Author Comment

by:pcox9999
ID: 24827255
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

0
 
LVL 37

Accepted Solution

by:
Geert Gruwez earned 500 total points
ID: 24830128
in formshow, the form is not allways visible yet

you don't need to self. everything

try this:

TfrmPatLookup.FormStyle := fsStayOnTop; // This is a must !

type
  TfrmPatLookup = class(TForm)
    procedure FormShow(Sender: TObject);
  private
    procedure WMFormShow(var Msg: TMessage); message WM_USER;
  end;

procedure TfrmPatLookup.FormShow(Sender: TObject);
begin
  PostMessage(Handle, WM_USER,  0, 0);
end;

procedure TfrmPatLookup.WMFormShow(var Msg: TMessage); message WM_USER;
begin
  BringToFront;
  ActiveControl := ePatient;
end;
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
TVirtualStringTree  search using TEdit 7 106
delphi prevent click fast 2 189
Working this component WebCopy with proxy, help 3 76
update joined tables 2 27
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
A short film showing how OnPage and Connectwise integration works.

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now