Based on your code snippet I created the following snippet, however no controls were returned.
Main Topics
Browse All TopicsI am using EnumWindows and EnumChildWindows to get the handles of all running applications.
Say I am looking for a specific ClassName(CN) or MainWindowTitle(MWT) and once I find it I want to iterate through the controls of that specific form. How can I do this?
Basically what I am looking to do is launch an application, wait for the CN or MWT to show up, change the selection in a specific dropdown combo box, click a button (which launches a new form), wait for its CN or MWT to show up, fill in a few textboxes, and click another button.
I obviously don't expect all that code, but if I can get the control handles and maybe an example of how to do any function (click a button) I should be able to figure out the rest.
I tried uploading a 2MB .Zip file of my project but needless to say just about every file extension wasn't in the list.
Added a .JPG, thought it might help. The code snippet is what populates 'Form1' of the .JPG
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Use Spy++ or the free WinSpector to explore the application further:
http://www.windows-spy.com
Do you get separate windows with these tools? Probably not. If this is the case then your options become much more limited!
Options?...
(1) Use a possibly less reliable automation process by injecting keystrokes. This could be simply like using SendKeys.Send() or more sophisticated with SendMessage() or SendInput().
(2) Use some kind of framework provided by "ScanIt". Is there an API, COM interface, ActiveX control etc?...
(3) Does the app allow any kind of automation via command-line switches?
The standard .Net Toolstrip also has Buttons on it where each Button does NOT have its own handle so I've tested with that.
The example below clicks at the point (45, 10) relative to the ToolStrip upper left corner. This clicked on the second button in my screenshot.
So all you need to do is figure out the handle to the ToolBar in your external app and then figure out the correct "offset" coords to click on:
I posted some different approaches here...
http://www.experts-exchang
Ok,
I'm going to award you the points but figured I'd ask a few more questions (on topic) if you don't mind.
Once I have the next form opened. I need to put some data in the text boxes. However, as I look at the Winspector information on the text boxes they all have the same ClassName and no MainWindowTitle. How do I figure out which text box is the one I am looking for? Or would you like me to ask as another question :)
Look at the .JPG. I am looking for the TCompactEdit.UnicodeClass that is expanded.
When you have more than one control of the same type (classname) then you can make multiple calls to FindWindowEx() to get the correct one:
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
(ByVal parent As IntPtr, ByVal child As IntPtr, _
ByVal className As String, ByVal caption As String) As IntPtr
So...
(1) Get a handle to the TdfInfoGroup.UnicodeClass "Order" control either using your enumerator code or thru FindWindow()/FindWindowEx(
Handle1 = somehow get the root window handle...
(2) Pass handle #1 to FindWindowEx() to get the TdfInfoPanel control:
Handle2 = FindWindowEx(Handle1, IntPtr.Zero, "TdInfopanel", Nothing)
(3) Get a handle to the First TdInfoRow:
Handle3 = FindWindowEx(Handle2, IntPtr.Zero, "TdInfoRow", Nothing)
(4) Pass Handle3 as the "child" using Handle2 as the parent to get the Second TdInfoRow:
Handle4 = FindWindowEx(Handle2, Handle3, "TdInfoRow", Nothing)
I coded this in the browser but I'm pretty sure it's correct.
Thanks for Step #5, I noticed it was missing but followed your example and figured the last step out.
The main issue I am having now is with calling the other form up.Once it is up using "LeftClickAt" the calling application is stuck waiting for LeftClickAt to return. I added a message box and it won't display until I close the form we called with LeftClickAt. So needless to say I can't interact with the form any further. Any suggestions?
The PostMessage() worked much better.
I had to use a combination of the EnumWindows, EnumChildWindows, and FindWindowsEx to accomplish it but your help was invaluable.
Here's the code I ended up with:
RadButton4_Click sends text to a control nested...
Form, Panel, Panel, Panel, Group, Group, Group, Group, Panel, Row, Row, Edit (Order No)
I included RadButton5_Click because it was the other fields I needed to populate and the way they were nested I had to use a slightly different approach and thought it might be helpful to someone in the future.
RadButton5_Click sends text to a control nested...
Form, Panel, Panel, Panel, Group, Group, Group, Panel, Row, Row, Row, Row, Row, Edit (Last Name), Row, Edit (First Name)
Awesome...glad you were able to put it all together!
The very nature of these types of questions make them the most difficult at EE to answer. Just getting the necessary preliminary information is tricky in itself...as the experts don't have the app in front of them to interrogate and experiment with.
As you've found out, there are a myriad of Win APIs and approaches that can be used...and often no concrete, clear path to which is best and/or whether a combination is needed.
Glad I was able to gently guide you in the right direction. It's obvious to me that you are a fairly proficient programmer who just needed some help with a new territory. =)
Business Accounts
Answer for Membership
by: Idle_MindPosted on 2009-07-03 at 09:25:35ID: 24773307
Did you get the WindowsEnumerator code from here? ces.live.c om/blog/ cn s!A0D71E16 14E8DBF8!2 17.entry
.List(Of WindowsEnumTest.ApiWindow) MainWindow Handle.ToI nt32) ' <--- using our instance of Process called "P"
http://kellychronicles.spa
If YOU are starting the application then simply pass the MainWindowHandle() property to the GetChildWindows() function:
Dim P As Process = Process.Start("calc")
P.WaitForInputIdle()
Dim childList As System.Collections.Generic
childList = winEnum.GetChildWindows(P.
For Each apiChild As WindowsEnumTest.ApiWindow In childList
RadTextBox3.Text += apiWin.MainWindowTitle + ":" + apiChild.MainWindowTitle + vbCrLf
Next
To click a button, you could use:
Private Const WM_LBUTTONDOWN As Integer = &H201
Private Const BM_SETSTATE As Integer = &HF3
Private Const BM_CLICK As Integer = &HF5
Private Const WM_LBUTTONUP As Integer = &H202
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
(ByVal parent As IntPtr, ByVal child As IntPtr, _
ByVal className As String, ByVal caption As String) As IntPtr
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal handle As IntPtr, ByVal uMsg As Integer, _
ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Private Sub ClickButton(ByVal handle As IntPtr)
Call SendMessage(handle, WM_LBUTTONDOWN, 0, 0)
Call SendMessage(handle, BM_SETSTATE, 1, 0)
Call SendMessage(handle, BM_CLICK, 0, 0)
Call SendMessage(handle, WM_LBUTTONUP, 0, 0)
End Sub