Always on top

From HashVB
Revision as of 16:03, 18 July 2008 by Dee (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
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