How to get the handle of the active window
Posted on January 4, 2009
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | 'System & API - How to get the handle of the active window Option Explicit Private Declare Function GetForegroundWindow Lib "user32" () As Long Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long Public Function GetActiveWindow(ByVal ReturnParent As Boolean) As Long Dim I As Long, J As Long I = GetForegroundWindow If ReturnParent Then Do While I <> 0 J = I I = GetParent(I) Loop I = J End If GetActiveWindow = I End Function |