Click to See Complete Forum and Search --> : Child Windows
Archon
Aug 12th, 2000, 04:01 PM
To Find the Handle of a Window you use the FindWindow API. But what would one use to find the handle of a Child Window?. Can somebody please Give me an example of finding a Child Window. Thanx
Use FindWindowEx. Next example will get the hWnd of the TextBox inside Notepad.
Private 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 FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Sub Command1_Click()
Dim hParent As Long
Dim hChild As Long
'Get the handle of Notepad
hParent = FindWindow("Notepad", vbNullString)
'Get the handle of the TextBox inside Notepad
hChild = FindWindowEx(hParent, 0&, "Edit", vbNullString)
End Sub
Archon
Aug 12th, 2000, 04:36 PM
Thank you Megatron you have been very helpful. Can you find a child window by its Class or by it't Title? is there an API for that?
Archon
Aug 12th, 2000, 04:39 PM
For Example: FindChildByTitle(hwnd,"")
or: FindChildByClass(hwnd,"")...
Yes, FindWindowEx allows for both. The last argument specifies the Window title and the 2nd last argument specifies the ClassName.
For example, if you wanted to find a Button, you would use
hChild = FindWindowEx(hParent, 0&, "Button", vbNullString)
If you wanted to find a window that has the text of "Hello!" you would use.
hChild = FindWindowEx(hParent, 0&, vbNullString, "Hello!")
agent
Aug 12th, 2000, 11:59 PM
Somebody goofed when they put together the winapi.txt file from the API Viewer
I found the following declaration for findwindowex much more descriptive:
Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWndParent As Long, ByVal hWndChildAfter As Long, ByVal lpClassName As String, ByVal lpWindowName As String) As Long
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.