Option Explicit
Private Const GW_HWNDNEXT = 2
Public Const WM_USER As Long = &H400
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal HWND As Long, lpdwProcessId As Long) As Long
Private Declare Function GetParent Lib "user32" (ByVal HWND As Long) As Long
Private Declare Function GetWindow Lib "user32" (ByVal HWND As Long, ByVal wCmd As Long) As Long
Public Declare Function DeleteObject Lib "gdi32.dll" (ByVal hObject As Long) As Long
Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" ( _
ByVal hWnd1 As Long, ByVal hWnd2 As Long, _
ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Public Function GetHwnd(ByVal PID As Long) As Long
' Return the window handle for an instance handle.
Dim lHwnd As Long
Dim test_pid As Long
Dim Thread_ID As Long
' Get the first window handle.
lHwnd = FindWindow("OWL_Window", vbNullString)
' Loop until we find the target or we run out
' of windows.
Do While lHwnd <> 0
' See if this window has a parent. If not,
' it is a top-level window.
If GetParent(lHwnd) = 0 Then
' This is a top-level window. See if
' it has the target instance handle.
Thread_ID = GetWindowThreadProcessId(lHwnd, test_pid)
If test_pid = PID Then
' This is the target.
GetHwnd = lHwnd
Exit Do
End If
End If
' Examine the next window.
lHwnd = GetWindow(lHwnd, GW_HWNDNEXT)
Loop
End Function
Thursday, December 18, 2008
Other Windows Handle
[Note: Use the specified code at your own risk,author is not responsible for any harm from the code]
Subscribe to:
Posts (Atom)