Click here to Skip to main content
15,907,497 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

How can I get the main window of a process using C#?

Updated 19-Feb-11 13:47pm
Sergey Alexandrovich Kryukov 19-Feb-11 20:37pm    
It doesn't look like a healthy or safe programming idea. May I as you why?

You start with the Process class to get the Process instance you're looking for. Then you can use it's MainWindowHandle property to get the handle to the apps startup form.
Share this answer
Sergey Alexandrovich Kryukov 19-Feb-11 19:33pm    
My 5. That said, processed does not "have" Forms.
[Adding to Dave's answer.]

You cannot use the handle returned from Process.MainWindowHandle with methods like Form.FromHandle because the handle is not already associated with a Control object in your application. Any interaction with that window will have to be through P/Invoking APIs like SetWindowText.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900