提取窗口的所有子窗口 [英] Extract all child windows of window
问题描述
我怎么能提取窗口的所有子窗口?
How can I extract all child windows of a window?
样品code:
Dim hWnd As IntPtr = ProcessName.MainWindowHandle
For Each hWndChild As IntPtr In hWnd
MsgBox(hWndChild.classname.tostring & ", Caption: " & hWndChild.caption.tostring())
Next
(如间谍++)
(like spy++)
推荐答案
正如其他人所说,你应该使用 EnumWindows的
和 EnumChildWindows
功能。
Just as others have suggested, you should use the EnumWindows
and EnumChildWindows
functions.
下面是一个链接,我刚刚从code片移植从另一个程序我写在VB6(很长一段时间以前)的小演示程序: 的Windows扫描仪
Here's a link to little demonstration program I just ported from pieces of code from another program I had written in VB6 (a very long time ago): Windows Scanner
希望它可以帮助...
Hope it helps...
编辑:我才意识到这不是太多的答案没有实际解释这些功能是如何工作的。所以,这里有云:
I just realized this wasn't much of an answer without actually explaining how those functions work. So, here it goes:
在 EnumWindows的
函数将作为其第一个参数,一个指向一个回调函数。
第二个参数是可以传递给回调函数的值。你可以把它看作是一个用户自定义的参数。
The EnumWindows
function takes as its first parameters a pointer to a callback function.
The second parameter is a value that you can pass to the callback function. You can think of it as a user-defined argument.
每次 EnumWindows的
发现一个新的窗口,它会调用回调函数来通知新的窗口。此回调函数作为参数,该窗口的处理程序和可选参数,当 EnumWindows的
首次被指定的用户。
Every time EnumWindows
"finds" a new window, it will call the callback function to inform about the new window. This callback function takes as parameters, the handler of the window and the optional parameter that the user specified when EnumWindows
was first called.
所以,基本上,这就是你怎么骂 EnumWindows的
:
So, basically, this is how you call EnumWindows
:
EnumWindows(New EnumWindowsProc(AddressOf EnumProc), 0)
其中, EnumWindowsProc
是用于创建一个引用 EnumProc
的功能,这将是我们的回调委托。
Where EnumWindowsProc
is a delegate used to create a reference to the EnumProc
function, which will be our callback.
这种回调的签名如下:
Private Function EnumProc(hWnd As IntPtr, lParam As IntPtr) As Boolean
有这个功能,你填入你的内部发现窗户数组中。
It is inside this function that you populate your internal array of discovered windows.
事情是pretty的大致相同的 EnumChildWindows
的功能,唯一的区别是,它的第一个参数必须是父窗口的句柄。
其他一切都在相同的方式处理。
Things are pretty much the same for the EnumChildWindows
function, with the only difference being that its first parameter must be the handler of the parent window.
Everything else is handled in the exact same way.
如果您检查 WindowsScanner
程序的源$ C $ C,你会看到,我甚至用相同的委托和相同的回调函数为 EnumWindows的
和 EnumChildWindows
。
那么,如何才能知道我们是否枚举顶层或子窗口?
很简单,我只需设置 EnumChildWindows
的最后一个参数为1。然后,该参数被传递给回调函数( EnumProc
),这使得它基于该参数的值,以采取不同的行动。
If you check the source code of the WindowsScanner
program, you will see that I even use the same delegate and the same callback function for both EnumWindows
and EnumChildWindows
.
So how do I know if we are enumerating top-level or child windows?
Easy, I simply set the last parameter of EnumChildWindows
to "1". Then, this parameter is passed to the callback function (EnumProc
) which allows it to take different actions based on the value of that parameter.
这篇关于提取窗口的所有子窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!