VB怎么枚举窗体中所有子窗体句柄

来源:百度知道 编辑:UC知道 时间:2024/05/29 06:41:01
spy++ 是什么?怎么用?VB怎么枚举窗体中所有子窗体句柄?

遍历窗口所有子窗体句柄,参考如下:
Private Type WndClassInfo '自定义的窗口类数据结构
lHandle As Long '返回的窗体句柄
pSAName As Long
pSACaption As Long
End Type

'(程序段,使用时应放入相应的Sub/Function中)
Dim tClsInfo As WndClassInfo
Dim bClsName() As Byte, bClsCaption() As Byte
bClsName = "要查的类名" '类名
bClsCaption = "要查的标题名"'标题名
With tClsInfo
.lHandle = 0&
Call CopyMemory(.pSAName, ByVal VarPtrArray(bClsName), 4)
Call CopyMemory(.pSACaption, ByVal VarPtrArray(bClsCaption), 4)
End With
Call EnumChildWindows(hwnd, AddressOf EnumChildProc, VarPtr(tClsInfo))

Private Function EnumChildProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean
Dim tClsInfo As WndClassInfo
Dim sTarName As String, sTarCaption As String '待查的目标类名及标题名
Dim bBuffer1() As Byte, bBuffer2() As Byte '数组,按字节存放字符串,用来克服 VB BSTR 跨函数调用的种种问题
Dim sBuffer1 As String, sBuffer2 As Str