|
-
May 29th, 2000, 04:24 PM
#1
Thread Starter
Lively Member
I have the handle of the parent window, but I can't find out how to get the handle of the child window within.
Anyone got any ideas,
Thanks in advance,
Steve.
-
May 29th, 2000, 05:55 PM
#2
Guru
FindWindowEx solves the problem.
Your question isn't specific, so I'll give you an example.
This will find the hWnd of Notepad, then the hWnd of the Edit control inside it (which is considered a child window), and finally, use that hWnd to set some text in Notepad, all when you click Command1.
Code:
Option Explicit
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWndParent As Long, ByVal hWndSearchAfter As Long, ByVal lpszClassName As String, ByVal lpszWindowName As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_SETTEXT = &HC
Private Sub Command1_Click()
Dim hWndNotepad As Long, hWndEdit As Long
' Equivalent to: hWndNotepad = FindWindow("Notepad", vbNullString)
hWndNotepad = FindWindowEx(0, 0, "Notepad", vbNullString)
' This will find the "Edit" inside "Notepad":
hWndEdit = FindWindowEx(hWndNotepad, 0, "Edit", vbNullString)
' Now, we can use the hWnd of the Edit:
Call SendMessage(hWndEdit, WM_SETTEXT, 0, ByVal "Yonatan's code is successful!")
End Sub
-
May 29th, 2000, 06:04 PM
#3
transcendental analytic
Code:
Private Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Private returnval(), counter%, Parent&
Private Function EnumFunction(ByVal hwnd&, ByVal lParam&) As Long
If GetParent(hwnd) <> Parent Then EnumFunction = True: Exit Function 'Exits if it's a indirect child
counter = counter + 1
ReDim Preserve returnval(counter - 1)
returnval(counter - 1) = hwnd
EnumFunction = True
End Function
' Returns an array containing the childwnds
Public Function Getchild(Parenthwnd&)
Parent = Parenthwnd
counter = 0
EnumChildWindows Parenthwnd, AddressOf EnumFunction, 0
If counter Then Getchild = returnval
End Function
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
May 29th, 2000, 06:12 PM
#4
transcendental analytic
Oops, Yonatan got ahead of me, while i was searching for my code, just change the smilies to ), they popped up because of this vbworld code [& )] error.
Ok this sample will enumerate the childwindows. But you need only to call the Getchild(Parenthwnd) function to get an array of all direct child to the parent.
Here a sample of how to use it:
Code:
Dim a,b&
a=getchild(me.hwnd)
for each b in a
msgbox b
next b
Note that a must be a variant, but you can use it as an array a()
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|