title: How to postmessage to an application with C# on Winforms?
body: <p>I am trying to make an application for routine projects;</p>
  
  <p>It is more like autogui,macro but when macro is running i should be able to do another things so i need two mouse and two keyboards at the sametime running
  one of for my use otherone should run in the application</p>
  
  <p>I can successfully post message to notepad with enter it to textbox
  but other applications not work like calculator,notepad++,discord,.. so on</p>
  
  <p>I need to send keyboard,mouse to current form application</p>
  
  <p>In both methods</p>
  
  <pre><code>    [DllImport("user32.dll", SetLastError = true)]
      static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
  
      [DllImport("user32.dll", SetLastError = true)]
      static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
  </code></pre>
  
  <p>First method</p>
  
  <pre><code>    [DllImport("User32.Dll", EntryPoint = "PostMessageA", SetLastError = true)]
      public static extern bool PostMessage(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam);
  
      public void control()
      {
          Process[] processes = Process.GetProcessesByName(textBox1.Text);
  
          foreach (Process p in processes)
          {
              textBox2.Text += p.ProcessName + System.Environment.NewLine;
              IntPtr windowHandle = p.MainWindowHandle;
              const int WM_KEYDOWN = 0x0100;
              const int VM_KEYUP = 0x0101;
              IntPtr editx = FindWindowEx(windowHandle, IntPtr.Zero, "edit", null);
              PostMessage(editx, WM_KEYDOWN, (IntPtr)66, IntPtr.Zero);
              PostMessage(editx, VM_KEYUP, (IntPtr)66, IntPtr.Zero);
          }
  
      }
  </code></pre>
  
  <p>Other tried method</p>
  
  <pre><code>    [DllImport("user32.dll")]
      private static extern bool PostMessage(IntPtr hWnd, UInt32 Msg, int wParam, Int32 lParam);
  
      public void control()
      {
              IntPtr handle = this.Handle;
              IntPtr handle2 = Handle;
              const int WM_KEYDOWN = 0x0100;
              const int VM_KEYUP = 0x0101;
              const int WM_MOUSEMOVE = 0x0200;
              const int WM_LBUTTONDOWN = 0x0201;
              const int WM_LBUTTONUP = 0x0202;
              IntPtr editx = FindWindowEx(handle , IntPtr.Zero, "edit", null);
              IntPtr editx2 = FindWindowEx(handle2, IntPtr.Zero, "edit", null);
  
              PostMessage(editx, WM_KEYDOWN, (Int32)Keys.S, 1);
              PostMessage(editx, VM_KEYUP, (Int32)Keys.S, 1);
              PostMessage(editx, WM_LBUTTONDOWN, 1, (280 &lt;&lt; 16) | 280);
              PostMessage(editx, WM_LBUTTONUP, 0, (280 &lt;&lt; 16) | 280);
              PostMessage(editx2, WM_KEYDOWN, (Int32)Keys.S, 1);
              PostMessage(editx2, VM_KEYUP, (Int32)Keys.S, 1);
              PostMessage(editx2, WM_LBUTTONDOWN, 1, (280 &lt;&lt; 16) | 280);
              PostMessage(editx2, WM_LBUTTONUP, 0, (280 &lt;&lt; 16) | 280);
      }
  </code></pre>
  
  <p>It can be about:</p>
  
  <pre><code>IntPtr editx = FindWindowEx(windowHandle, IntPtr.Zero, "edit", null);
  </code></pre>
  
  <p>What can i write instead edit and how can i find it ?</p>
  
  <p>I tried to trace what i giving to GetProcessesByName("") with textBox2.Text ,
  i am sure about process names are true</p>
  
  <p>Even to make sure about used method i send to all related names with for</p>
  
  <p>So what is wrong about this method ?</p>
  
  <p>Why it is not working on other applications ?</p>