title: How to send text to Notepad in C#/Win32?
body: <p>I'm trying to use SendMessage to Notepad, so that I can insert written text without making Notepad the active window.</p>
  
  <p>I have done something like this in the past using <code>SendText</code>, but that required giving Notepad focus.</p>
  
  <p>Now, first I'm retrieving the Windows handle:</p>
  
  <pre><code>Process[] processes = Process.GetProcessesByName("notepad");
  Console.WriteLine(processes[0].MainWindowHandle.ToString());
  </code></pre>
  
  <p>I've confirmed it's the right handle for Notepad, the same shown within <code>Windows Task Manager</code>.</p>
  
  <pre><code>[DllImport("User32.dll", EntryPoint = "SendMessage")]
  public static extern int SendMessage(int hWnd, int Msg, int wParam, int lParam);
  </code></pre>
  
  <p>From here, I haven't been able to get SendMessage to work in all my experimentation.  Am I going in the wrong direction?</p>