I am using the Win32 API call SetForegroundWindow
to set focus to another application's window. I am then using SendKeys
to send keystrokes to that window.
This works well apart from when a modal window (such as a File Open dialog) is open. In this scenario I want to set that modal child window as the foreground window.
Using my main application's hWnd, how can I set any modal child window as the active window? (Note that there may be a modal child that itself has another modal child open, so ideally I would like things to work in this scenario as well).
I am coding this in C#, .NET 3.5.