-
I am using:
Code:
X = FindWindowEx(hwnd, 0&, "RICHEDIT", vbNullString)
to get the hWnd of one the rich edit boxes on a form of another program so I can send text to. This works fine, the problem I have is there are two rich edit boxes on the form how do I get the other rich edit box hWnd?
-
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
Public Function Getchild(Parenthwnd&)
Parent = Parenthwnd
counter = 0
EnumChildWindows Parenthwnd, AddressOf EnumFunction, 0
If counter Then Getchild = returnval
End Function
You could enumerate the child windows of your form and check for their classnames, catch both richtextboxes and check for their specific size or position to determine which one it is :)
-
Once again Kedaman you rule!!
Thanks
-
Or you can still use FindWindowEx function by looping through all children that's class name is RICHEDIT:
Code:
Dim lngChildHwnd As Long
Dim arrChildren() As Long
Dim i As Integer
lngChildHwnd = 1
Do until lngChildHwnd = 0
lngChildHwnd = FindWindowEx(ParentHwnd, lngChildHwnd, "RICHEDIT", vbNullString)
If lngChildHwnd Then
Redim Preserve arrChildren(i)
arrChildren(i) = lngChildHwnd
i = i + 1
End If
Loop
arrChildren now holds window handles of all RICHEDIT children (assuming that ParentHwnd is a parent window handle).
-
Yep, but Serge seems to have found a better solution! ;)
-
I can't get serge's solution to work though it will only find the first hWnd then it stops.
-
Are you sure you pass a parent that has more then 1 RICHEDIT child???
-
Positive I used spy++ and both are named RICHEDIT and they both have different hWnds
-
Hmm I tried the same and didn't get any handles of the Richtextboxes at all, are you sure the arguments are correct?
-
It's hard to say if it's working correctly or not, since I don't know what application you're trying to use to send the text to.
This code was tested with the form and 5 RichTextboxes sitting on it. It has created an array with 5 elements. Even though classname of the RichTextBox in VB is different, it shouldn't be any different then to look for RICHEDIT.
[Edited by Serge on 10-20-2000 at 07:25 PM]