如何获取另一个进程MessageBox的消息?

时间:2014-03-15 17:53:52

标签: c# c++ window messagebox

另一个应用程序有时会显示带有标题“Test”的MessageBox和MessageBox体内的一些消息,我如何从另一个应用程序(在C ++或C#上写入)获取此消息然后关闭它? C#中的代码:

[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[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;

for (int i = 0; i < 40; i++) // just test cycle
{
     IntPtr window = FindWindow(null, "Test");
     if (window != IntPtr.Zero) // ok we found it!
     {
          // code that reads MessageBox message?
          .....
          // work is done, closing
          SendMessage((int)window, WM_SYSCOMMAND, SC_CLOSE, 0);
          break;
     }
     System.Threading.Thread.Sleep(50);
}

你能帮我解决这个问题吗?我该怎么办?

1 个答案:

答案 0 :(得分:1)

查看this thread

选择1:

  

您可以使用Spy++之类的API访问其他Windows控件。

选择2:

  

你应该使用像EnumWindow或FindWindow这样的Windows API然后使用   EnumChildWindows API用于查找目标窗口中的控件,如   您要查找的文本框,然后是API SetWindowText

     

在这里查看一些想法:Why is EnumChildWindows skipping children?还在Stack Overflow中搜索这些API名称   你会发现很多例子......

选择3:

  

我发现这个api可以让你完成你的任务:   http://www.programmersheaven.com/download/56171/download.aspx