我有一个程序需要将 BM_CLICK 消息发送到另一个应用程序按钮。我可以获取父窗口句柄,但是当我尝试获取按钮句柄时,如果总是返回 0
我从 Spy++ 获得了按钮标题名称和按钮类型,这似乎是对的,但我知道我一定是搞错了。下面是我的代码
public const Int BM_CLICK = 0x00F5;
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr SendMessage(IntPtr hwnd, uint Msg, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
private void button1_Click(object sender, EventArgs e)
{
Process[] processes = Process.GetProcessesByName("QSXer");
foreach (Process p in processes)
{
////the Button's Caption is "Send" and it is a "Button".
IntPtr ButtonHandle = FindWindowEx(p.MainWindowHandle, IntPtr.Zero, "Button", "Send");
//ButtonHandle is always zero thats where I think the problem is
SendMessage(ButtonHandle, BM_CLICK, IntPtr.Zero, IntPtr.Zero);
}
}
间谍屏幕截图