[Tutorial] Make Window Always On top
As the tittle says i will explain how to make the window allways on top.
Put that in a module
Quote:
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
Now in ur Form declarations
Quote:
Private Const HWND_BOTTOM = 1
Private Const HWND_NOTOPMOST = -2
Private Const HWND_TOP = 0
Private Const HWND_TOPMOST = -1
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
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
Now Put that 2 functions:
Quote:
Public Sub MakeWindowAlwaysTop(hWnd As Long)
SetWindowPos hWnd, HWND_TOPMOST, 0, 0, 0, 0, _
SWP_NOMOVE + SWP_NOSIZE
Form1.Visible = True
End Sub
Public Sub MakeWindowNotTop(hWnd As Long)
SetWindowPos hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, _
SWP_NOMOVE + SWP_NOSIZE
Form1.Visible = False
End Sub
And finally if u want to make it on top/or not:
Quote:
MakeWindowAlwaysTop (hWnd) 'TO MAKE IT ON TOP
MakeWindowNotTop (hWnd) 'NOT ON TOP
Or with HOTKEYS:
Quote:
Private Sub Timer1_Timer()
If GetAsyncKeyState(vbKeyQ) <> 0 Then 'OR UR KEY
MakeWindowAlwaysTop (hWnd)
form1.visible=true
ElseIf GetAsyncKeyState(vbKeyW) <> 0 Then 'OR UR KEY
MakeWindowNotTop (hWnd)
Form1.visible=false
End If
End Sub