I noticed that setforegroundwindow can be very flaky - no matter how you do it.
I noticed that using UIAutomation, where possible, seems to improve the situation.
For instance:
Getting WindowPattern and using something like:
windowPattern.SetWindowVisualState( WindowVisualState.Normal ); windowPattern.SetWindowVisualState( WindowVisualState.Maximized );
Now my questions are:
How to find out if I should do this as much as possible or normally. The task manager and the dragon naturally both seem to know how to do this. If it was previously maximized and then minimized, I would like to enlarge the window when I switch to it. If this had not previously been maximized, I would like to make it "Normal."
Any ideas?
Derek source share