使用GetWindow的代码如下:Option ExplicitPrivate 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 LongPrivate Sub Form_Load() EnumChild Me.hwnd End SubPublic 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
For Each Item In Me.Controls
If Item Is TextBox
MsgBox Item.hWnd
End If
...
' 这里可以递归调用
Next
我的MSDN里 怎么没有 API函数 和windows程序呢
http://download.csdn.net/source/160152
http://topic.csdn.net/u/20090316/18/29aa77dd-c789-4f89-a7db-b4e274e0fcab.html
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 LongPrivate Sub Form_Load()
EnumChild Me.hwnd
End SubPublic 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 呀 ~