gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 11:38:03 26 4
gpt4 key购买 nike

另一个应用程序有时会显示标题为“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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com