枚举窗口内的子窗口句柄、类名

'Code By 魑魅魍魉
'mailto:[email protected]

Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long


Private Const GW_CHILD = 5
Private Const GW_HWNDNEXT = 2


Private Sub Form_Load()
Dim Hwd, Cla As Long
Dim Lon As String
Lon = Space(255)
Hwd = GetWindow(Me.hwnd, GW_CHILD)  '取得第1个子窗口句柄
Me.Caption = Hwd
Do While Hwd <> 0  '  如果句柄<>0循环
 Cla = GetClassName(Hwd, Lon, 255)   '取得这个子窗口的类名
 List1.AddItem Hwd & "   " & Trim$(Lon)  '将句柄和类名+到LIST1
 Hwd = GetWindow(Hwd, GW_HWNDNEXT)  '查找下一个
Loop
End Sub

你可能感兴趣的:(源码)