Link to home
Start Free TrialLog in
Avatar of ShadowHawk071998
ShadowHawk071998

asked on

BringToFront doesn't really work on forms...

Hi Guys.
I have a form that is acting as a timer. You put in on minimize, and after a few minutes it should pop back up. I want it to come on top of everything you have open, and display a message (Like Outlook reminders).

But I can't make my form on top of all other forms. I put the following lines -

     WindowState := wsNormal     ;
     Show;
     Application.BringToFront;
     showmessage('Time to do XXX');

But none of these help. What am I missing?

T.
Avatar of Imagine
Imagine

This will put your form ontop:

SetWindowPos(Handle,HWND_TOPMOST,Left,Top,Width,Height,0); //on top
Cant you just set the formstyle to fsStayOnTop, so after you restore it, it'll come to the top on its own?
Try this ....

if you use this the form will show aswell

 - The SWP_SHOWWINDOW will display the window

SetWindowPos(form1.handle,hwnd_TopMost,0,0,0,0,SWP_SHOWWINDOW);
 - Places the window above all non-topmost windows.
   The window maintains its topmost position even when    
   it is deactivated.


SetWindowPos(form1.handle,hwnd_NoTopMost,0,0,0,0,SWP_SHOWWINDOW);
  - Places the window above all non-topmost windows (that
    is, behind all topmost windows).
    This flag has no effect if the window is already a non-
    topmost window.

SetWindowPos(form1.handle,hwnd_Top,0,0,0,0,SWP_SHOWWINDOW);
  - Places the window at the top of the Z order.

Try this ....

if you use this the form will show aswell

 - The SWP_SHOWWINDOW will display the window

SetWindowPos(form1.handle,hwnd_TopMost,0,0,0,0,SWP_SHOWWINDOW);
 - Places the window above all non-topmost windows.
   The window maintains its topmost position even when    
   it is deactivated.


SetWindowPos(form1.handle,hwnd_NoTopMost,0,0,0,0,SWP_SHOWWINDOW);
  - Places the window above all non-topmost windows (that
    is, behind all topmost windows).
    This flag has no effect if the window is already a non-
    topmost window.

SetWindowPos(form1.handle,hwnd_Top,0,0,0,0,SWP_SHOWWINDOW);
  - Places the window at the top of the Z order.

ASKER CERTIFIED SOLUTION
Avatar of SteveWaite
SteveWaite

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I did not read the question throug :(.

SteveWaite's code will work the best.

Go Steve! :)
SetWindowPos(): Left, Top, Width, 0 are of the main form, with height of zero you get (nearly) the proper animation when restoring.

Regards
Steve  
Avatar of ShadowHawk071998

ASKER

Hey guys.
None of these solution actually worked. Sorry. I guess it may come from the fact I need to display a message as well. I did find an elegant solution - I show my message as a modal window - this pops it on top, and I have the message displayed. Cool.

Will this work on Win95/98 as well? (I have win2K).

What should I do with the question?
Maybe it's from the fact you use ShowMessage()?  If you use MessageBox() from the Windows API you can specify the parent handle.  Don't quote me, but I think if you give a handle of 0, that uses the desktop and will make the dialog shown on top of all other windows.
Actually the show modal is even preferable to teh MessageBox - it's more pretty.
But maybe I'll try that.

T.
Yes it will work the same in winX.

:)

ShadowHawk:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.