How to do so?
Also is there a function where we can enumerate all child of a window?
I use FindWindowEx but sometimes it "skip" a window.
Printable View
How to do so?
Also is there a function where we can enumerate all child of a window?
I use FindWindowEx but sometimes it "skip" a window.
Is this question still valid?. You have another thread that is very similar.
Replace the "Debug.Print" lines with code that checks whether the text is the text your program is looking for in a window.Code:Option Explicit
Public Const WM_GETTEXT As Long = &HD&
Public Const WM_GETTEXTLENGTH As Long = &HE&
Public Declare Function EnumChildWindows Lib "User32.dll" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Public Declare Function EnumWindows Lib "User32.dll" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Public Declare Function SendMessageA Lib "User32.dll" (ByVal hwnd As Long, ByVal Msg As Long, wParam As Any, lParam As Any) As Long
Public Function GetWindowText(WindowH As Long) As String
Dim Length As Long
Dim Text As String
Text = String$(SendMessageA(WindowH, WM_GETTEXTLENGTH, ByVal CLng(0), ByVal CLng(0)) + 1, vbNullChar)
Length = SendMessageA(WindowH, WM_GETTEXT, ByVal Len(Text), ByVal Text)
GetWindowText = Left$(Text, Length)
End Function
Public Function HandleChildWindows(ByVal hwnd As Long, ByVal lParam As Long) As Long
Debug.Print GetWindowText(hwnd)
HandleChildWindows = CLng(True)
End Function
Public Function HandleWindows(ByVal hwnd As Long, ByVal lParam As Long) As Long
Debug.Print GetWindowText(hwnd)
EnumChildWindows hwnd, AddressOf HandleChildWindows, CLng(0)
HandleWindows = CLng(True)
End Function
Public Sub Main()
EnumWindows AddressOf HandleWindows, CLng(0)
End Sub
I figured that out.
Enumwindow is one way.
Another is to use findwindowex with vbnullstring