Is there a way to get the window handle (IntPtr) for a window after its launched from a C# app with Process.Start()?
4 Answers
If it's the main window you're after, Process.MainWindowHandle will give you what you need.
Comments
Use
process.MainWindowHandle;
It probably is 0 when launching the app, so you might want to loop and sleep until it is filled up.
2 Comments
This is not a recent topic but the answers are incomplete.
I agree with the Process.MainWindowHandle solution and to wait for the value but not with Sleep.
If you have just started a process and want to use its main window handle, consider using the WaitForInputIdle method to allow the process to finish starting, ensuring that the main window handle has been created.
This overload applies only to processes with a user interface and, therefore, a message loop.
4 Comments
Process.WaitForInputIdle seems to return almost immediately if it's used on a WPF application. I believe this is due to the WPF internals...