Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2010
  • Last Modified:

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.
0
ShadowHawk071998
Asked:
ShadowHawk071998
  • 4
  • 2
  • 2
  • +5
1 Solution
 
ImagineCommented:
This will put your form ontop:

SetWindowPos(Handle,HWND_TOPMOST,Left,Top,Width,Height,0); //on top
0
 
mocartsCommented:
0
 
MannSoftCommented:
Cant you just set the formstyle to fsStayOnTop, so after you restore it, it'll come to the top on its own?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
HoratioHCommented:
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.

0
 
HoratioHCommented:
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.

0
 
SteveWaiteCommented:
 ShowWindow(Application.Handle, SW_RESTORE);
  SetWindowPos(Application.Handle, HWND_TOP, Left, Top, Width, 0, SWP_NOZORDER);
  Application.RestoreTopMosts;
  Application.Restore;

Regards
Steve
0
 
HoratioHCommented:
I did not read the question throug :(.

SteveWaite's code will work the best.

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

Regards
Steve  
0
 
ShadowHawk071998Author Commented:
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?
0
 
MannSoftCommented:
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.
0
 
ShadowHawk071998Author Commented:
Actually the show modal is even preferable to teh MessageBox - it's more pretty.
But maybe I'll try that.

T.
0
 
HoratioHCommented:
Yes it will work the same in winX.

:)

0
 
CleanupPingCommented:
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.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 2
  • 2
  • +5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now