1 Attachment(s)
Find a combobox from another application in nested form.
Please help I have been through this back and forth and I can't seem to figure out where it went wrong.
Can someone figure this out? I want to extract the Static.string from another application.
Code:
'Get handle of all sibling child windows that have the same parent(Top-level window).
Dim Parent_hWnd As Int32
Dim cwnd As Int32
Dim dwnd As Int32
Dim ewnd As Int32
Dim fwnd As Int32
Dim gwnd As Int32
Dim iwnd As Int32
Dim jwnd As Int32
Dim kwnd As Int32
Parent_hWnd = apiFindWindowEx(HWND_DESKTOP, 0, Nothing, "Remote Management Agent Facility")
If Parent_hWnd = 0 Then
'This is another possibility.
Parent_hWnd = apiFindWindowEx(HWND_DESKTOP, 0, Nothing, "Remote Management")
If Parent_hWnd = 0 Then
'This is an attempt to find the registered class.
Parent_hWnd = apiFindWindowEx(HWND_DESKTOP, 0, "WindowsForms10.Window.8.app.0.378734a", Nothing)
End If
End If
'10x Steps
cwnd = apiFindWindowEx(Parent_hWnd, 0, "WindowsForms10.Window.8.app.0.378734a", Nothing)
cwnd = apiFindWindowEx(Parent_hWnd, 0, "WindowsForms10.Window.8.app.0.378734a", Nothing)
cwnd = apiFindWindowEx(Parent_hWnd, 0, "WindowsForms10.Window.8.app.0.378734a", Nothing)
cwnd = apiFindWindowEx(Parent_hWnd, 0, "WindowsForms10.Window.8.app.0.378734a", Nothing)
cwnd = apiFindWindowEx(Parent_hWnd, 0, "WindowsForms10.Window.8.app.0.378734a", Nothing)
cwnd = apiFindWindowEx(Parent_hWnd, 0, "WindowsForms10.Window.8.app.0.378734a", Nothing)
cwnd = apiFindWindowEx(Parent_hWnd, 0, "WindowsForms10.Window.8.app.0.378734a", Nothing)
cwnd = apiFindWindowEx(Parent_hWnd, 0, "WindowsForms10.Window.8.app.0.378734a", Nothing)
cwnd = apiFindWindowEx(Parent_hWnd, 0, "WindowsForms10.Window.8.app.0.378734a", Nothing)
cwnd = apiFindWindowEx(Parent_hWnd, 0, "WindowsForms10.Window.8.app.0.378734a", Nothing)
dwnd = apiFindWindowEx(cwnd, 0, "WindowsForms10.Window.8.app.0.378734a", Nothing)
ewnd = apiFindWindowEx(dwnd, 0, "WindowsForms10.Window.8.app.0.378734a", Nothing)
fwnd = apiFindWindowEx(ewnd, 0, "WindowsForms10.Window.8.app.0.378734a", Nothing)
'2x Steps
gwnd = apiFindWindowEx(fwnd, 0, "WindowsForms10.Window.8.app.0.378734a", Nothing)
gwnd = apiFindWindowEx(fwnd, 0, "WindowsForms10.Window.8.app.0.378734a", Nothing)
'4x Steps
iwnd = apiFindWindowEx(gwnd, 0, "WindowsForms10.Window.8.app.0.378734a", Nothing)
iwnd = apiFindWindowEx(gwnd, 0, "WindowsForms10.Window.8.app.0.378734a", Nothing)
iwnd = apiFindWindowEx(gwnd, 0, "WindowsForms10.Window.8.app.0.378734a", Nothing)
iwnd = apiFindWindowEx(gwnd, 0, "WindowsForms10.Window.8.app.0.378734a", Nothing)
'2x Steps
jwnd = apiFindWindowEx(iwnd, 0, "WindowsForms10.Window.8.app.0.378734a", Nothing)
jwnd = apiFindWindowEx(iwnd, 0, "WindowsForms10.Window.8.app.0.378734a", Nothing)
'FOUND YOU!
kwnd = apiFindWindowEx(jwnd, 0, "WindowsForms10.STATIC.app.0.378734a", Nothing)
System.Threading.Thread.Sleep(1) 'Give a chance to see the new handle
Dim s As New StringBuilder(256)
GetWindowText(kwnd, s, s.Capacity)
Return s.ToString()
1 Attachment(s)
Re: Find a combobox from another application in nested form.
Can someone help?
The position of the mdi changed durring run time. How would you be able to grab it correctly?
Re: Find a combobox from another application in nested form.
Get the handles of all windows and use GetWindowTitle on each. See my last post
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.
Nope it the actual handle I want shifting from 7 to 10 then 17 then 13 when user move their mdi dockable content.
So sometime it work if z-order move to 7 then when it move out of that z-order it stop working. This is pissing me off. I can't pin it down.
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.
1 Attachment(s)
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
Re: Find a combobox from another application in nested form.
I don't know if you can go back twice but once you find the handle of the "Queue:" label (Static), you use that handle with the GetParent api.
Code:
Private Declare Auto Function GetParent Lib "user32" _
(ByVal hWnd As IntPtr) As IntPtr
You now have the handle of the parent so you use FindWindowEx 3 times and check when you get the handle of the other Static.
If you want to brute-force it, use the 2 APIs on every handle from the list
GetClassName by Handle
GetWindowText
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
EnumChildWindows(parent.hWnd, Nothing, "WindowsForms10.STATIC.app.0.378734a", "Queue:")
I want something like this and just drill down all the class hierarchy and find it first then I think I can figure out how to get parent.
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.