【发布时间】:2014-03-15 17:53:51
【问题描述】:
另一个应用程序有时会在 MessageBox 正文中显示标题为“Test”的 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);
}
你能帮我解决这个问题吗?我该怎么做?
【问题讨论】:
标签: c# c++ window messagebox