Question

I'm working on a program to simultaneously control a handful of other programs of the same type.

So far I use EnumWindows() and collect the handles of the appropriate windows(programs) that I'm going to be controlling. Upon recognizing some keyboard keystroke, I iterate through all of the programs(there could be any number of them open) and I post click messages to all of these programs simultaneously by using EnumChildWindows() to find the appropriate windows(buttons) based on which keystroke was pressed and then using PostMessage() to actually send the click.

Each of these programs that I'm controlling has a button named "Load Settings" which opens an Open file dialog when clicked. What I would like to do is first use PostMessage() to click "Load Settings"(I have successfully gotten this far, what follows is what I'm trying to do). Then I want to get the handle of that Open file dialog window, fill in the text field with the path to the appropriate settings file that I've already determined, then click the "Open" button to finish the task and close the Open window.

My main problem is finding that Open window. Now, I can use EnumWindows once again to find that window but the problem with this is upon clicking "Load Settings" the Open window doesn't open instantaneously. I could sleep after clicking the button, then enum through the windows to find it, but that's not practical as the window could take any amount of time to open.

I've used spy++ to gather some information about this window, but as far as I know, none of it helps enough. Anyways, here is what I have found:

  • The window "Open" is the Previous Window to the program which it was opened from.
  • The window "Open"'s parent is the program which it was opened from.
  • The window "Open"'s owner is the program which it was opened from.

But even though it's listed as a child of the main program under its window properties, it's listed on the same level as the main program (it's not nested like other child windows).

I've tried FindWindowEx() and EnumChildWindows() but neither could find the Open window.

I would think there should be some way to, based on some handle, get the handle of the previous window.

Once that's working, then I need to fill the Edit(text field) window with the appropriate file path.

Was it helpful?

Solution

UIA is what you want, if your goal is to automate UI actions (e.g. for testing). UIA exposes the entire UIA tree which contains all applications active on the machine.

So what you'll see is a root node which has one child node for each application. Each of those nodes should represent the top level window of that application. Any further children depend on the application itself.

See more info at UIA Overview

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top