Is there an API function that will return the window handle of the window that currently has the focus on the desktop ?
Printable View
Is there an API function that will return the window handle of the window that currently has the focus on the desktop ?
Sure, it's GetForeGroundWindow(), example:
private Declare Function GetForegroundWindow Lib "user32" () as Long
private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (byval hwnd as Long, byval lpString as string, byval cch as Long) as Long
private Sub Form_Load()
Timer1.Interval = 100
End Sub
private Sub Timer1_Timer()
static lHwnd as Long
Dim lCurHwnd as Long
Dim sText as string * 255
lCurHwnd = GetForegroundWindow
If lCurHwnd = lHwnd then Exit Sub
lHwnd = lCurHwnd
If lHwnd <> hwnd then
Caption = "ActiveWidow: " & Left$(sText, GetWindowText(lHwnd, byval sText, 255))
else
Caption = "ActiveWindow: Form1"
End If
End Sub
Aaron Young
Analyst Programmer
[email protected]
[email protected]