?
Solved

BringToFront doesn't really work on forms...

Posted on 2003-03-30
14
Medium Priority
?
1,856 Views
Last Modified: 2010-04-04
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
Comment
Question by:ShadowHawk071998
[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
  • 4
  • 2
  • 2
  • +5
14 Comments
 

Expert Comment

by:Imagine
ID: 8234749
This will put your form ontop:

SetWindowPos(Handle,HWND_TOPMOST,Left,Top,Width,Height,0); //on top
0
 
LVL 9

Expert Comment

by:mocarts
ID: 8235003
0
 
LVL 6

Expert Comment

by:MannSoft
ID: 8235213
Cant you just set the formstyle to fsStayOnTop, so after you restore it, it'll come to the top on its own?
0
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!

 
LVL 9

Expert Comment

by:tkalchev
ID: 8237757
0
 

Expert Comment

by:HoratioH
ID: 8238368
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
 

Expert Comment

by:HoratioH
ID: 8238529
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
 
LVL 3

Accepted Solution

by:
SteveWaite earned 500 total points
ID: 8239443
 ShowWindow(Application.Handle, SW_RESTORE);
  SetWindowPos(Application.Handle, HWND_TOP, Left, Top, Width, 0, SWP_NOZORDER);
  Application.RestoreTopMosts;
  Application.Restore;

Regards
Steve
0
 

Expert Comment

by:HoratioH
ID: 8243596
I did not read the question throug :(.

SteveWaite's code will work the best.

Go Steve! :)
0
 
LVL 3

Expert Comment

by:SteveWaite
ID: 8245642
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
 

Author Comment

by:ShadowHawk071998
ID: 8247274
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
 
LVL 6

Expert Comment

by:MannSoft
ID: 8247553
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
 

Author Comment

by:ShadowHawk071998
ID: 8247630
Actually the show modal is even preferable to teh MessageBox - it's more pretty.
But maybe I'll try that.

T.
0
 

Expert Comment

by:HoratioH
ID: 8251530
Yes it will work the same in winX.

:)

0
 

Expert Comment

by:CleanupPing
ID: 9316539
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

Introducing Priority Question

Increase expert visibility of your issues by participating in Priority Question, our latest feature for Premium and Team Account holders. Adjust the priority of your question to get emergent issues in front of subject-matter experts for help when you need it most.

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
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

770 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