|
-
Dec 13th, 1999, 07:08 AM
#1
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)
-
Dec 13th, 1999, 11:18 AM
#2
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).]
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
|