title: How do you get a Process' main window handle in C#?
body: <p>The objective is to programmatically start a Windows Form, get its handle, and send info to its wndProc() function using Win Api's SendMessage() function.</p>
  
  <p>I got the SendMessage() part taken care of but the problem now is getting the form's handle after the process has been started.</p>
  
  <p>My first guess was that Process' MainWindowHandle property would get me the handle I am looking for, but after I start the process MainWindowHandle remains equal to 0 and the following code doesn't show the handle of the process I just started:</p>
  
  <pre><code>foreach (Process p in Process.GetProcesses())
  {
  Console.WriteLine(p.MainWindowHandle);
  }
  </code></pre>
  
  <p>Can someone tell me how to do this and whether it can actually be done?</p>