close a message box from another program using c#

后端 未结 2 1986
长发绾君心
长发绾君心 2020-12-10 14:41

Here\'s my problem: we have an automated build process for our product. During the compilation of one of the VB6 projects a message box is spit out that requires the user t

2条回答
  •  轮回少年
    2020-12-10 15:37

    You have to found the window, that is the first step. After you can send the SC_CLOSE message using SendMessage.

    Sample

    [DllImport("user32.dll")]
    Public static extern int SendMessage(int hWnd,uint Msg,int wParam,int lParam);
    public const int WM_SYSCOMMAND = 0x0112;
    public const int SC_CLOSE = 0xF060;
    
    IntPtr window = FindWindow(null, "Location Browser Error");
    if (window != IntPtr.Zero)
    {
       Console.WriteLine("Window found, closing...");
    
       SendMessage((int) window, WM_SYSCOMMAND, SC_CLOSE, 0);  
    }
    

    More Information

    • Find and Close the window using WIN API

提交回复
热议问题