Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the form of a childprocess

Tags:

c#

.net

forms

i am trying to get the main form of a process that i started, but the FromChildHandle and FromHandle always return null. the MainWindowHandle however is nonzero.

IntPtr p = process_wrapper.MainWindowHandle;
Form form = (Form) Control.FromChildHandle(p);
if (form != null)
{
    form.Close();
}
like image 425
clamp Avatar asked Aug 08 '13 10:08

clamp


1 Answers

You can only retrieve a form as a control, if the form in question has been generated by your application. You cannot retrieve a form from another process, as your parent process is not aware of the handle <->Control mapping of the child process.

If you just want to "stop" the child process (form.close() ?) You can simple stop the complete process. Either "Clean", or by force:

process.CloseMainWindow() vs process.kill()

like image 120
dognose Avatar answered Nov 09 '22 01:11

dognose