Difference between revisions of "Always on top"

From HashVB
Jump to: navigation, search
 
(How to make a window "Always on top")
Line 1: Line 1:
Yeah, working on it..
+
If you want to make a window "Always on top" then all you need is one single call API call:
  
Dee
+
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==
 +
* [http://www.earlsoft.co.uk/api/call.php?name=SetWindowPos Earlsoft API page]
 +
* [http://msdn.microsoft.com/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowfunctions/setwindowpos.asp MSDN page]

Revision as of 20:57, 10 October 2005

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