Difference between revisions of "Always on top"

From HashVB
Jump to: navigation, search
(How to make a window "Always on top")
m (Reverted edit of MonroLvipa, changed back to last version by Dee)
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 +
{{VB6}}
 
If you want to make a window "Always on top" then all you need is one single call API call:
 
If you want to make a window "Always on top" then all you need is one single call API call:
  
Line 17: Line 18:
  
 
==See also==
 
==See also==
* [http://www.earlsoft.co.uk/api/call.php?name=SetWindowPos Earlsoft API page]
+
* {{API link|SetWindowPos}}
 
* [http://msdn.microsoft.com/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowfunctions/setwindowpos.asp MSDN page]
 
* [http://msdn.microsoft.com/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowfunctions/setwindowpos.asp MSDN page]

Latest revision as of 16:03, 18 July 2008

float
 This article is based on Visual Basic 6. Find other Visual Basic 6 articles.

If you want to make a window "Always on top" then all you need is one single call API call:

Declare Function SetWindowPos Lib "user32" (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

This function can be used for a number of things but the item of interest to us is setting the Z-Order

Const HWND_TOPMOST = -1
SetWindowPos FormName.hWnd, HWND_TOPMOST, 0, 0, 0, 0, &H1 Or &H2

The &H1 and &H2 translate to SWP_NOSIZE and SWP_NOMOVE which tells SetWindowPos to ignore the size and position paramaters as you only want to change the Z-Order.

To set it back to the normal state, you need to pass HWND_NOTOPMOST

Const HWND_NOTOPMOST = -2

See also