GFSetWindowOnTop/GFSetWindowOnTop.frm
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3195
ClientLeft = 60
ClientTop = 315
ClientWidth = 4635
LinkTopic = "Form1"
ScaleHeight = 3195
ScaleWidth = 4635
StartUpPosition = 3 'Windows‑Standard
Begin VB.CommandButton Command5
Caption = "Is On Top ?"
Height = 315
Left = 1680
TabIndex = 3
Top = 2820
Width = 1335
End
Begin VB.CommandButton Command4
Caption = "Hide for 1 sec."
Height = 315
Left = 3060
TabIndex = 0
Top = 1860
Width = 1515
End
Begin VB.Timer Timer1
Enabled = 0 'False
Interval = 1000
Left = 0
Top = 0
End
Begin VB.CommandButton Command3
Caption = "Disable for 1 sec."
Height = 315
Left = 3060
TabIndex = 1
Top = 2340
Width = 1515
End
Begin VB.CommandButton Command2
Caption = "From Top"
Height = 315
Left = 3060
TabIndex = 4
Top = 2820
Width = 1515
End
Begin VB.CommandButton Command1
Caption = "On Top"
Height = 315
Left = 120
TabIndex = 2
Top = 2820
Width = 1515
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
'(c)2000 by Louis (v1.1).
'Note that from now on the variable prefix 'GF' (General Function) is in use.
'[GFSetWindowOnTop/GFRemoveWindowFromTop]
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
'GFIsWindowOnTop
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
'[GFSetWindowOnTop/GFRemoveWindowFromTop]
Private Const HWND_TOPMOST As Long = ‑1
Private Const HWND_NOTOPMOST As Long = ‑2
Private Const SWP_NOSIZE As Long = &H1
Private Const SWP_NOMOVE As Long = &H2
'GFIsWindowOnTop
Private Const GW_HWNDPREV As Long = 3
Private Function GFSetWindowOnTop(ByRef WindowOrFormName As Form) As Long
'on error resume next
GFSetWindowOnTop = SetWindowPos(WindowOrFormName.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE)
WindowOrFormName.Refresh
End Function
Private Function GFRemoveWindowFromTop(ByRef WindowOrFormName As Form) As Long
'on error resume next
GFRemoveWindowFromTop = SetWindowPos(WindowOrFormName.hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE)
WindowOrFormName.Refresh
End Function
Private Function GFIsWindowOnTop(ByRef WindowOrFormName As Form) As Boolean
'on error resume next
GFIsWindowOnTop = (GetWindow(WindowOrFormName.hwnd, GW_HWNDPREV) = 0)
End Function
Private Sub Command1_Click()
'on error resume next
Form2.Enabled = True
Form2.Visible = True
Call GFSetWindowOnTop(Form1)
Call GFSetWindowOnTop(Form2)
End Sub
Private Sub Command2_Click()
'on error resume next
Call GFRemoveWindowFromTop(Form1)
End Sub
Private Sub Command3_Click()
'on error resume next
Timer1.Enabled = True
Form1.Enabled = False
End Sub
Private Sub Command4_Click()
'on error resume next
Timer1.Enabled = True
Form1.Visible = False
End Sub
Private Sub Command5_Click()
'on error resume next
Form2.Enabled = True
Form2.Visible = True
Form2.SetFocus
Debug.Print GFIsWindowOnTop(Form1) '***TEMP*** (does not work if TopMost window doesn't have the focus)
End Sub
Private Sub Timer1_Timer()
'on error resume next
Timer1.Enabled = False 'reset
Form1.Enabled = True
Form1.Visible = True
End Sub
[END OF FILE]