Re: Find a combobox from another application in nested form.
When you said get handles you mean the windows HEX value?
Doesn't that change everytime the software reload?
I read your bit it just pull all handles to list. It doesn't really find the right one. I'm confuse. Some class will have the same names, how would you distinguish between them?
How would you know to get &H2055E in the first place?
This code for reference only.
Code:
Private Declare Auto Function FindWindowEx Lib "user32" _
(ByVal parentHandle As IntPtr, ByVal childAfter As IntPtr, _
ByVal ClassName As String, ByVal WindowTitle As String) As IntPtr
'2055E was the handle from the screenshot, replace it with the current one
Dim ImportantHandle As IntPtr
ImportantHandle = FindWindowEx(New IntPtr(&H2055E), IntPtr.Zero, "RichEdit20A", "210036")
Dim Result As String
Result = System.Convert.ToString(ImportantHandle.ToInt32, 16)
MessageBox.Show(ImportantHandle.ToString)
Re: Find a combobox from another application in nested form.
Well, once you get all the handles you check if the handle of the control you are interested in is always at the same place, for example if it is always the 20th handle from the list. If it is, you only have to call GetWindowText on the 20th handle.
So, is the order constant between restarts of the app?
Re: Find a combobox from another application in nested form.
How exactly can you identify this window by looking at the screen? That's how you identify it in code. It doesn't look like they have different titles so you can't use that. Presumably you look at the windows and you identify the one you want by the controls it contains. That's exactly what you have to do in code. You get the handle of the first child window and then you check what child controls it has. If it has the correct set of child controls then it's the right window, otherwise you move on to the next. You just have to keep getting handles until you have enough information to uniquely identify the window you're after.
Re: Find a combobox from another application in nested form.
The blue one is the only one I know for sure. Is it then possible to EnumChildWindows and find it then go back twice?
How would I use EnumChildWindows to find "class" "label" for nested child?
Code:
Dim enumerator As New WindowsEnumerator
For Each parent As ApiWindow In enumerator.GetTopLevelWindows("WindowsForms10.Window.8.app.0.378734a")
MsgBox(parent.MainWindowTitle)
For Each child As ApiWindow In enumerator.GetChildWindows(parent.hWnd, "WindowsForms10.STATIC.app.0.378734a")
MsgBox(" " & child.MainWindowTitle)
Next child
Next parent
Last edited by Crayfish; May 6th, 2009 at 01:01 AM.
Re: Find a combobox from another application in nested form.
What function would I use to drill it down to that sibbling of the parent in the first place?
That is the problem I am having.
Code:
Function EnumChildWindows(ByVal hParent As Long, _
ByVal EnumProc As Long, ByVal lParam As Long) As Long
Dim hChild As Long
Dim Continue As Boolean
Continue = AddressOf EnumProc(hParent, lParam)
hChild = FindWindowX(hParent, 0, 0, 0)
While hChild And Continue
Continue = EnumChildWindows(hChild, 0, 0) ' recursive call!
hChild = FindWindowX(hParent, hChild, 0, 0)
Wend
EnumChildWindows = Continue
End Function
Re: Find a combobox from another application in nested form.
You're talking about a tree so you should be using recursion. Each time a recursive call returns you are inherently "going back" up the branch one level.
Re: Find a combobox from another application in nested form.
I'm thinking of a dirty way to do this...and I came up with a messy code. Logically it seems to work. I am going to test it out tomorrow at work. If it works ill post the code and see if you guys can clean it up a bit.