我一直试图在程序中找到特定帮助按钮的句柄,然后向它发送 BN_CLICK 消息。为了调试,我查看了父窗口和按钮的句柄。
[DllImport("User32.dll", EntryPoint = "FindWindow")]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("User32.dll", EntryPoint = "FindWindowEx")]
private static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string lclassName, string windowTitle);
public Form1()
{
IntPtr hWndParent = FindWindow("WindowsForms10.Window.8.app.0.2c040a7_r9_ad1", null);
Debug.WriteLine(hWndParent,"\n");
IntPtr button = FindWindowEx(hWndParent, IntPtr.Zero, "WindowsForms10.BUTTON.app.0.2c040a7_r9_ad1", "Help");
Debug.WriteLine(button);
}
调试为 hWndParent 返回一个数字,但为按钮返回 0。我从 Spy++ 获得了课程。 1
这可能会因为应用程序中有两个具有相同类的“帮助”按钮而变得复杂。这是我正在尝试使用帮助按钮获取句柄的应用程序窗口的图片,我想单击以红色框突出显示的帮助按钮。2
我尝试添加通过 AutoIT Info 获得的实例编号。
IntPtr button = FindWindowEx(hWndParent, IntPtr.Zero, "WindowsForms10.BUTTON.app.0.2c040a7_r9_ad113", "Help");
这也为按钮返回了 0,将“帮助”替换为 null 也是如此。如果有人熟悉从 Windows 10 窗体获取句柄并知道如何执行此操作,我们将不胜感激。谢谢!
安德鲁