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

我想在C#中创建与spy ++相同的function“Find windows …”。 我试过WINAPI的这个function:

HWND WINAPI WindowFromPoint(__in POINT Point); 

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

例如,在程序员模式下使用窗口7计算器,如果它们被禁用,我无法使用我的程序获得“ABCDEF”,那么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函数的小例子,或者知道我的代码不起作用? thanx你的答案


我试图创建循环,但似乎句柄在另一个句柄下,但不是句柄的子句,循环总是发送相同的句柄,并且当禁用键“abcdef”时没有所需的子句。 你有另一个想法吗?

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

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


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

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