哪位可以提供一下,枚举法获得某窗体内控件句柄的例程吗?
窗体句柄已经知道了,可以通过此句柄,枚举出其内的各类控件的句柄吗?比如文本框类,和按钮类,菜单类及子菜单。
能帮帮忙吗? --------------------编程问答-------------------- EnumChildWindows() API
或者
For Each Item In Me.Controls
If Item Is TextBox
MsgBox Item.hWnd
End If
...
' 这里可以递归调用
Next --------------------编程问答-------------------- 老大可以在详细一点吗?谢谢了
我的MSDN里 怎么没有 API函数 和windows程序呢 --------------------编程问答-------------------- Mark
--------------------编程问答-------------------- up~ --------------------编程问答-------------------- 给你个源码的链接参考一下吧:
http://download.csdn.net/source/160152
--------------------编程问答-------------------- 参考:
http://topic.csdn.net/u/20090316/18/29aa77dd-c789-4f89-a7db-b4e274e0fcab.html --------------------编程问答-------------------- 使用FindWindow+FindWindowEx或者GetWindow都行。 --------------------编程问答-------------------- 使用GetWindow的代码如下:
--------------------编程问答-------------------- up~~~ --------------------编程问答-------------------- 顶一下!
Option Explicit
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Const GW_HWNDNEXT = 2
Private Const GW_HWNDPREV = 3
Private Const GW_CHILD = 5
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Sub Form_Load()
EnumChild Me.hwnd
End Sub
Public Sub EnumChild(ByVal hParent As Long)
Dim hChild As Long
Dim lRet As Long
Dim strClassName As String
hChild = GetWindow(hParent, GW_CHILD)
Do While hChild <> 0
strClassName = String(200, vbNullChar)
lRet = GetClassName(hChild, strClassName, Len(strClassName))
strClassName = Left(strClassName, lRet)
Debug.Print hChild, strClassName
Call EnumChild(hChild)
hChild = GetWindow(hChild, GW_HWNDNEXT)
Loop
End Sub
是不是用 FindWindow 和 GetWindow 呀 ~
补充:VB , API