SendMessage and WM_CLOSE
<p>I am creating a simple C# app to monitor vended application on the server and if any message boxes come up with a particular window name to close the window and continue with the process. 
Vendor has informational message boxes come up randomly which hangs the application until X or OK buttons are clicked. There are two types of message boxes that come up and one gets closed with no problem using my application but the other one does not. They both look very similar its just that one has embedded sql text as part of the message. Both of the Message Boxes are found by FindWindow its just when the SendMessage gets run it does not close the second type of the message box even though it sees it. I have also tried PostMessage and I get the same issue. </p>

<p>This is what I have:  </p>

<pre><code>    private const int WM_CLOSE = 0x10;

    [DllImport("user32.dll", CharSet = CharSet.Auto)]
    private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
    [DllImport("user32.dll", CharSet = CharSet.Auto)]
    public static extern int SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);

    IntPtr ErrorPopUp = FindWindow(null, WindowToClose.Trim());
                        if (ErrorPopUp != IntPtr.Zero) {
                            try {
                                Thread.Sleep(200);
                                SendMessage(ErrorPopUp, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
                                _WMExceptionDal.LogErrorMsg(_WMException);

                            } catch (Exception ex) {
                                _WMException.txt_iferror = "Unable to close the popup window";
                                _WMException.txt_sqlerrtext = ex.ToString();
                                _WMExceptionDal.LogErrorMsg(_WMException);
                            }
                        }
</code></pre>

<p>Any suggestions of other approach or if I am doing something wrong of why some message boxes would get closed by WM_CLOSE and why some wouldn't I would really appreciate it. </p>
