【问题标题】:How to get message of another process MessageBox?如何获取另一个进程MessageBox的消息?
【发布时间】: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


【解决方案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

【讨论】:

  • 选择 #3 链接已失效 - 您还有其他详细信息可以帮助找到该下载吗?
猜你喜欢
  • 1970-01-01
  • 2016-11-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-09-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多