Hi,
I would like to see if my form
is the top in the Zorder of the
other programs in the computer.
Can someone give me the code to
do that?
(Not Forms in MY program.. Other
Programs.. )
Printable View
Hi,
I would like to see if my form
is the top in the Zorder of the
other programs in the computer.
Can someone give me the code to
do that?
(Not Forms in MY program.. Other
Programs.. )
Use the GetForegroundWindow api function.
Of course, your program will always be on top because it has the focus, so you can use the GetAsyncKeyState api function to detect key presses.Code:Declare Function GetForegroundWindow Lib "user32.dll" () As Long
Private Sub Command1_Click()
Dim hforewnd As Long
Dim handl As Long
handl = Me.hWnd
hforewnd = GetForegroundWindow()
If handl = hforewnd Then
MsgBox "Your program is on top of all others!"
Else
MsgBox "Your program is not on top of all others!"
End If
End Sub
Code:Private Declare Function GetAsyncKeyState _
Lib "user32" (ByVal vKey As Long) As Integer
Private Sub Form_Load()
Timer1.Interval = 100
End Sub
Private Sub Timer1_Timer()
'Detect Tab key
If GetAsyncKeyState(vbKeyTab) Then
Command1_Click
End If
End Sub