Click to See Complete Forum and Search --> : Always on Top


yaronb
July 31st, 2001, 09:40 AM
Hi,
How can I make a form stay always on top ? (In similiar to Windows Clock utility).

Yaron.

Ghost308
July 31st, 2001, 09:51 AM
put this in a module..


private 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

'constants for SetWindowPos API
private Const SWP_NOMOVE = 2
private Const SWP_NOSIZE = 1
private Const HWND_TOPMOST = -1
private Const HWND_NOTOPMOST = -2

public Sub SetOnTop(byval hwnd as Long, byval bSetOnTop as Boolean)

Dim lR as Long
If bSetOnTop then
lR = SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or _
SWP_NOSIZE)
else
lR = SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or _
SWP_NOSIZE)
End If
End Sub






Then in your form load event..


private Sub Form_Load()
'keep form on top of everything
SetOnTop me.hwnd, true
End Sub