-
Keeping Program on Top
I am making a game where I have one form as a background form. I wish to keep that form on top of all other forms, except other forms my game brings up. So, I have frmStartup (background/main options) which needs to be on top, then any msgboxs or my frmNewGame needs to be above that.
-
Call like
OnTop (Me.hwnd), True
Code:
Declare Sub 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)
Public Sub OnTop(Handle As Long, Pos As Long)
Dim wFlags As Long, PosFlag As Long
Const Swp_Nosize = &H1
Const SWP_Nomove = &H2
Const Swp_NoActivate = &H10
Const Swp_ShowWindow = &H40
Const Hwnd_TopMost = -1
Const Hwnd_NoTopMost = -2
wFlags = SWP_Nomove Or Swp_Nosize Or Swp_ShowWindow
Select Case Pos
Case True
PosFlag = Hwnd_TopMost
Case False
PosFlag = Hwnd_NoTopMost
End Select
SetWindowPos Handle, PosFlag, 0, 0, 0, 0, wFlags
End Sub
Greg