在C#中创建spy ++的函数“find window ...”

时间:2012-02-29 23:46:44

标签: c# winapi spy++ findwindow

我想创建相同的功能"查找窗口......"在C#中使用间谍++。 我试过WINAPI的这个功能:

HWND WINAPI WindowFromPoint(__in  POINT Point);

http://msdn.microsoft.com/en-US/library/ms633558.aspx 但是我不能通过它获得所有元素,因为它们被禁用或隐藏。

例如,在程序员模式下使用窗口7计算器,我无法获得" A B C D E F" 如果他们被禁用,我的程序,间谍++可以得到它。

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

[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函数的小例子,或者知道我的代码不起作用? thanx你的答案


我已经尝试创建循环但是,似乎句柄在另一个句柄下但不是句柄的子句,循环总是发送相同的句柄而没有所需的孩子当键#34; a b c d e f"被禁用。你还有其他想法吗?

1 个答案:

答案 0 :(得分:5)

WindowFromPoint返回一个窗口句柄。由于您正在处理已禁用/隐藏的窗口,因此您需要使用ChildWindowFromPointEx,将hwndParent作为从WindowFromPoint获得的任何句柄传递。

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


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

注意:这是WinAPI的做事方式。我不知道C#提供的API是什么或者是什么。