Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Always on top?

Status
Not open for further replies.

Alt255

Programmer
May 14, 1999
1,846
US
Does anyone know an API call to give a VB6 form the AlwaysOnTop property? Zorder doesn't work when trying to dominate the windows of other apps.<br>
I need to present a message to the users, center owner, at a critical moment, regardless of the type and number of windows opened at the time.<br>
The users will REALLY want to see the message but I haven't had much luck going front and center over some windows.<br>
Any ideas?
 
Thanks, DougP! I'll give it a try.
 
Option Explicit<br>
Private Declare Function SetWindowPos Lib &quot;user32&quot; (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long<br>
<br>
Private Const SWP_NOMOVE = 2<br>
Private Const SWP_NOSIZE = 1<br>
Private Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE<br>
Private Const HWND_TOPMOST = -1<br>
Private Const HWND_NOTOPMOST = -2<br>
<br>
Form_Load :<br>
<br>
Call SetWindowPos(Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS)<br>
<br>
Eric<br>
<p>Eric De Decker<br><a href=mailto:vbg.be@vbgroup.nl>vbg.be@vbgroup.nl</a><br><a href= Visual Basic Center</a><br>
 
Just an addition to Eric's reply - when I used this a while ago I found that I had to call SetWindowPos from a number of different events (inc the form resize event as I remember) to ensure it stayed on top.<br>
<br>
This behaviour could easily depend upon which version of windows you are running.<br>
<br>
Mike<br>
<p>Mike Lacey<br><a href=mailto:Mike_Lacey@Cargill.Com>Mike_Lacey@Cargill.Com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
That may be the case. The floating property is lost when the window is minimized but it doesn't always seem to return when the window is restored with SetWindowsPos in the resize event. (Sort of like DougP's original answer, mysteriously missing from this thread.)<br>
So far, I've only played with the function under '98 (original) and it seems to work well enough, as long as you keep the user from fiddling with the window.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top