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

标签 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);
}

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

最佳答案

查看 this thread .

选择 1:

You can use an API like Spy++ to access other windows controls.

选择 2:

you should use Windows APIs like EnumWindow or FindWindow then use EnumChildWindows API to find the controls in the target window, like the textbox you are looking for, then the API SetWindowText

have a look here for some ideas: Why is EnumChildWindows skipping children? also search for these APIs names here in Stack Overflow and you will find many examples...

选择 3:

I found this api which may allow you to complete your task : http://www.programmersheaven.com/download/56171/download.aspx

关于c# - 如何获取另一个进程MessageBox的消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22427565/

相关文章:

c# - 将子节点添加到节点列表

c# - 枚举所有 "always on top"的窗口

Java:将 JFrame 焦点转移到另一个 JFrame

c# - .net 正则表达式转换为 java @"(?&lt;!\\)(?' M'[^|%])"?

C# IDictionary.Keys 和 IDictionary.Values : what is the most optimal implementation?

c# - Xamarin Forms IsVisible false 占用空间

c++ - 在 C++ 中作为参数的多态(通用)函数

c++ - 使用 SFML 在第二台显示器上打开全屏窗口?

c++ - 与 Visual Studio 6.0 相关

graphics - 启动 arch 时出现 nouveau 错误