I've read a lot about this but can't seem to get the code to work.
I don't have SPy++ but here the window I am trying to access:
I have attempted multiple examples of this:
With this example I was expecting it to loop through all of the child windows of "Home (Search)". I'm getting an error on Me.hwnd since it is in a module. What do I need to replace Me with for this to execute properly?Code:Option Explicit On 'test module for accessing third party windows Module Module2 Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) 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 Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hWnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long Public Sub Form_Load() Dim lRet As Long lRet = FindWindow(vbNullString, "Home (Search)") If lRet = 0 Then Exit Sub lRet = FindWindowEx(me.hwand, lRet, vbNullString, vbNullString) Do While lRet <> 0 ShowWindowInfo(lRet) lRet = FindWindowEx(me.hwand, lRet, vbNullString, vbNullString) Loop End Sub Private Sub ShowWindowInfo(ByVal hWnd As Long) Dim lRet As Long Dim buffer As String Dim message As String message = "Window handle: " & hWnd & vbCrLf buffer = Space(256) lRet = GetWindowText(hWnd, buffer, 256&) message = message & "Window text: " & Left$(buffer, lRet) & vbCrLf buffer = Space(256) lRet = GetClassName(hWnd, buffer, 256&) message = message & "Class name: " & Left$(buffer, lRet) & vbCrLf Debug.Print(message) End Sub


Reply With Quote
