4

我想在 C# 中创建与 spy++ 相同的函数“查找窗口...”。我尝试过使用 WINAPI 的这个功能:

HWND WINAPI WindowFromPoint(__in  POINT Point);

http://msdn.microsoft.com/en-US/library/ms633558.aspx 但我没有到达所有元素,因为它们被禁用或隐藏。

例如,在程序员模式下使用窗口 7 计算器,如果它们被禁用,我无法使用我的程序获取“ABCDE F”,那么 spy++ 可以获取它。

编辑:我试过这个,但它不工作:

[DllImport("user32.dll")]
public static extern ulong GetClassLongPtr(IntPtr hWnd, int nIndex);

[DllImport("user32.dll")]
public static extern IntPtr ChildWindowFromPointEx(IntPtr hWndParent, Win32Point pt, uint uFlags);

IntPtr hWnd = WindowFromPoint(myPoint);
hWnd= ChildWindowFromPointEx(hWnd , myPoint, 0x0000);

myPoint 是我鼠标的位置。

我不熟悉WINAPI,我想你的解释是对我缺乏了解。有可能有一个 ChildWindowFromPointEx 函数的小例子,或者知道我的代码不起作用吗?谢谢你的回答


我尝试创建循环,但似乎句柄在另一个句柄下但不是句柄的子句柄,当键“abcde f”被禁用时,循环总是发送相同的句柄并且没有期望的子句。你有别的想法吗?

4

1 回答 1

5

WindowFromPoint返回一个窗口句柄。由于您正在处理禁用/隐藏的窗口,因此您需要使用ChildWindowFromPointExhwndParent作为您从WindowFromPoint.

您可能会发现以下文章很有帮助:http: //blogs.msdn.com/b/oldnewthing/archive/2010/12/30/10110077.aspx


关于您添加的代码,ChildWindowFromPointEx采用客户端坐标,而您拥有的鼠标位置坐标是屏幕坐标。您可以使用ScreenToClient进行转换。

Note: This is the WinAPI way to do things. I have no idea whether or what APIs C# supplies.

于 2012-02-29T23:51:53.133 回答