Solved

SetWindowPos causes taskbar button to flash

Posted on 2009-07-10
5
899 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 38

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 38

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 38

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

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 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…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses
Course of the Month8 days, 23 hours left to enroll

617 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