dogarila
Mechanical
- Oct 28, 2001
- 594
How do I make a VisualBasic form stay on top of SW window (be visible all the time with SW window maximized)?
Andrew
Andrew
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Const SWP_NOSIZE = &H1
Const SWP_NOMOVE = &H2
Const HWND_TOPMOST = -1
Const HWND_NOTOPMOST = -2
Public 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
Public Sub ForceWindowOnTop(hwnd As Long, bTrueFalse As Boolean)
Dim i
If bTrueFalse = True Then
i = SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE)
Else
i = SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE)
End If
End Sub
'Then, to call it from a Form:
Private Sub Form_Load()
Call ForceWindowOnTop(Me.hwnd, True)
End Sub
'To turn it off, just use False
Call ForceWindowOnTop(Me.hwnd, True)
Const SWP_NOSIZE = &H1
Const SWP_NOMOVE = &H2
Const HWND_TOPMOST = -1
Const HWND_NOTOPMOST = -2
Public 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
Public Sub ForceWindowOnTop(hwnd As Long, bTrueFalse As Boolean)
Dim i
If bTrueFalse = True Then
i = SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE)
Else
i = SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE)
End If
End Sub
'Then, to call it from a Form:
Private Sub Form_Load()
Call ForceWindowOnTop(Me.hwnd, True)
End Sub
'To turn it off, just use False
Call ForceWindowOnTop(Me.hwnd, False)