Solved

SetWindowPos causes taskbar button to flash

Posted on 2009-07-10
5
878 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 36

Expert Comment

by:Geert Gruwez
Comment Utility
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
Comment Utility
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 36

Expert Comment

by:Geert Gruwez
Comment Utility
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
Comment Utility
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 36

Accepted Solution

by:
Geert Gruwez earned 500 total points
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

743 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

20 Experts available now in Live!

Get 1:1 Help Now