question

akhirabahiraUK-2155 avatar image
0 Votes"
akhirabahiraUK-2155 asked akhirabahiraUK-2155 edited

How do you detect a window appearing without focus?

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.


dotnet-csharp
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

Castorix31 avatar image
0 Votes"
Castorix31 answered Castorix31 edited

You can use SetWinEventHook with OBJID_WINDOW and for example EVENT_OBJECT_CREATE




5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.