Kind of a special case problem:
- I start a process with
System.Diagnostics.Process.Start(..) - The process opens a splash screen — this splash screen becomes the main window.
- The splash screen closes and the ‘real’ UI is shown. The main window (splash screen) is now invalid.
- I still have the Process object, and I can query its handle, module, etc. But the main window handle is now invalid.
I need to get the process’s UI (or UI handle) at this point. Assume I cannot change the behavior of the process to make this any easier (or saner).
I have looked around online but I’ll admit I didn’t look for more than an hour. Seemed like it should be somewhat trivial 🙁
If you don’t mind using the Windows API, you could use
EnumWindowsProc, and check each of the handles that that turns up usingGetWindowThreadProcessId(to see that it’s in your process), and then maybeIsWindowVisible,GetWindowCaptionandGetWindowTextLengthto determine whichhWndin your process is the one you want.Though if you haven’t used those functions before that approach will be a real pain, so hopefully there’s a simpler way.