Solved

SetWindowPos causes taskbar button to flash

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
delphi exception 7 68
How to debug For loops? 3 57
Find and Replace Stream with 0s 8 69
Delphi and Access based Enumeration 9 70
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 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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

827 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