-
I need to get the handle of a button. I know the window caption and even the button caption, but I don't know the descending "child-tree" from the window to the button. Also, there are unknown classes in the tree. I can't easily recreate the event to use Spy++.
Can someone post the code to do some kind of nested or recursive FindWindowEx to find my button's hwnd? Remember, I don't know how far down my button is a descendent and I don't know which classes to follow down the tree. We can assume that there will be only one such button. FindWindowEx seems to search only the specified "sibling-level".
This format would be excellent:
MyDesiredHwnd = YourCoolFunction(MyKnownWindowCaption, MyKnownButtonCaption)
-
If you mean that you want to find the button on the form (by giving the form caption) then you can use something like this:
Code:
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
Public Function YourCoolFunction(pstrFormCaption As String, pstrButtonCaption As String) As Long
Dim lFormHwnd As Long
lFormHwnd = FindWindowEx(0, 0, vbNullString, pstrFormCaption)
YourCoolFunction = FindWindowEx(lFormHwnd, 0, vbNullString, pstrButtonCaption)
End Function
Example: Hwnd = YourCoolFunction("My Form", "My Button")
hWnd - now holds the window handle of your button.
Of course, it is better to use Class Name instead of the Caption.
------------------
Serge
Software Developer
[email protected]
[email protected]
ICQ#: 51055819
[This message has been edited by Serge (edited 12-13-1999).]