Difference between revisions of "Always on top"

From HashVB
Jump to: navigation, search
(elclisitd)
m (Reverted edit of MonroLvipa, changed back to last version by Dee)
 
Line 1: Line 1:
ordomrol
 
 
{{VB6}}
 
{{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:

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