PDA

Click to See Complete Forum and Search --> : Nested or Recursive FindWindowEx


Dec 13th, 1999, 06:08 AM
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)

Serge
Dec 13th, 1999, 10:18 AM
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:


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
Serge_Dymkov@vertexinc.com
Access8484@aol.com
ICQ#: 51055819 (http://www.icq.com/51055819)



[This message has been edited by Serge (edited 12-13-1999).]