Code:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Integer, ByVal hWnd2 As Integer, ByVal lpsz1 As String, ByVal lpsz2 As String) As Integer
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Integer, ByVal lpString As String, ByVal cch As Integer) As Integer
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hWnd As Integer, ByVal lpClassName As String, ByVal nMaxCount As Integer) As Integer
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As String) As Integer
Public Sub main()
Dim lngParent As Integer
Dim lngChild As Integer
Dim lngChild2 As Integer
Dim lngChild3 As Integer
Dim cReturn As Long, lParam As Long, parHwnd As Long
'I'm walking down the window tree until I find the control that I need
lngParent = FindWindow(vbNullString, "xxx- Home (Search)")
If lngParent <> 0 Then
ShowWindowInfo(lngParent)
lngParent = FindWindowEx(lngParent, 0, "MDIClient", vbNullString)
ShowWindowInfo(lngParent)
lngParent = FindWindowEx(lngParent, 0, vbNullString, "Home (Search)")
ShowWindowInfo(lngParent)
lngParent = FindWindowEx(lngParent, 0, "AfxMDIFrame70", vbNullString)
ShowWindowInfo(lngParent)
lngParent = FindWindowEx(lngParent, 0, "AfxFrameOrView70", vbNullString)
ShowWindowInfo(lngParent)
lngParent = FindWindowEx(lngParent, 0, "SysTabControl32", vbNullString)
ShowWindowInfo(lngParent)
lngParent = FindWindowEx(lngParent, 0, vbNullString, "Home")
ShowWindowInfo(lngParent)
lngChild = FindWindowEx(lngParent, 0, "GXWND", vbNullString)
ShowWindowInfo(lngChild)
lngChild2 = FindWindowEx(lngParent, lngChild, "GXWND", vbNullString)
ShowWindowInfo(lngChild2)
lngChild3 = FindWindowEx(lngParent, lngChild2, "GXWND", vbNullString)
ShowWindowInfo(lngChild3)
End if
End sub
Private Sub ShowWindowInfo(ByVal hWnd As Integer)
Dim lRet As Integer
Dim buffer As String
Dim message As String
Dim j As Integer
Dim wtext As String
Const WM_GETTEXT = &HD
Const LB_GETCOUNT = &H18B
wtext = Space(256)
j = SendMessage(hWnd, WM_GETTEXT, 255, wtext)
wtext = Left(wtext, j)
message = "Window handle: " & hWnd & vbCrLf
buffer = Space(256)
lRet = GetWindowText(hWnd, buffer, 256&)
message = message & "Window text: " & Left$(wtext, j) & " also: " & lRet & vbCrLf
buffer = Space(256)
lRet = GetClassName(hWnd, buffer, 256&)
message = message & "Class name: " & Left$(buffer, lRet) & vbCrLf
Debug.Print(message)
End Sub