I'm using UI Automation with installation wizards, specifically the FocusChangedEvent to catch when new windows appear on the desktop so I can interact with the buttons and elements. However, I've found that this doesn't catch some windows.
For example, this one gets detected by the event handler when it pops up: FireFox Setup Wizard
But this one does not: 7-Zip Setup Wizard
I'm not completely sure ASP.net why this is, though I suspect it has to do with the type of window and perhaps the elements on it that don't get detected. I've also tried checking for a WindowOpenedEvent with no luck. Is there any other alternative that I've missed?
This is the code I have right now:
public void Startup()
{
Automation.AddAutomationFocusChangedEventHandler(OnFocusChanged);
Automation.AddAutomationEventHandler(
WindowPattern.WindowOpenedEvent,
AutomationElement.FromHandle(_process.MainWindowHandle),
TreeScope.Subtree,
new AutomationEventHandler(OnFocusChanged));
}
Edit: I'm exploring non-UI Automation ways to do this now. Looking at the MainWindowHandle of the process I run doesn't always work because it often spawns a child process that is the one actually responsible for the UI, so the only way I can think of doing this right now is to check the MainWindowHandle of every child process.