title: Click on 'OK' button of message box using WINAPI in c#
body: <p>I am trying to click on 'OK' button on a message box of C# windows form using winapi. Below is the code that I am working on. </p>
  
  <pre><code>private const int WM_CLOSE = 16;
  private const int BN_CLICKED = 245;
  
  [DllImport("user32.dll", CharSet=CharSet.Auto)]
          public static extern int SendMessage(int hWnd, int msg, int wParam, IntPtr lParam);
  
  [DllImport("user32.dll", SetLastError = true)]
          public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string className,  string  windowTitle);
  
  //this works
  hwnd = FindWindow(null, "Message");
  if(hwnd!=0)
        SendMessage(hwnd, WM_CLOSE, 0, IntPtr.Zero);
  
  //this doesn't work.
  hwndChild = FindWindowEx((IntPtr)hwnd, IntPtr.Zero, "Button", "ok");
  SendMessage((int)hwndChild, BN_CLICKED, 0, IntPtr.Zero);
  </code></pre>
  
  <p>Though i get a value in <code>hwndChild</code>, it is not recognising <code>BN_CLICKED</code>.
  I am not sure what am I missing. any help?</p>
  
  <p>I am trying to close the message box button of another application and this is what I am doing. But, I m still missing something.</p>
  
  <pre><code>IntPtr hwndChild = IntPtr.Zero;
  hwndChild = FindWindowEx((IntPtr)hwnd, IntPtr.Zero,' '"Button", "OK");
  SendMessage((int)hwndChild, WM_COMMAND, (BN_CLICKED '&lt;&lt;16) | IDOK, hwndChild);
  </code></pre>