CodeItBetter Programming Another VB Programming Blog

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

Related posts:

  1. How to get the title of the Active Window
  2. How to check if a task exists by searching for (part or all of) the window title
  3. How to bring an external window to top using its caption
  4. How to get the window title of external application
  5. How to get Caption and Thread ID of Window under cursor
  6. How to handle Size & Position of Console Application with Windows Application in VB6
  7. How to bring our Window to the foreground
  8. How to clear the text in active control if the active form name is “frmCustomer”
  9. How to window caption to flash repeatedly
  10. Check & Terminate Process using Window Title

Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


No trackbacks yet.