Solved

SetWindowPos causes taskbar button to flash

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

774 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