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

spy++是什么?怎么用?VB怎么枚举窗体中所有子窗体句柄?... spy++ 是什么?怎么用?VB怎么枚举窗体中所有子窗体句柄? 展开
 我来答
百度网友e9042513a
2009-04-14 · TA获得超过6984个赞
知道大有可为答主
回答量:2388
采纳率:0%
帮助的人:3511万
展开全部
VB 遍历窗口所有子窗体句柄

Private Const GW_CHILD = 5
Private Const GW_HWNDFIRST = 0
Private Const GW_HWNDNEXT = 2

Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Private Declare Function IsWindow Lib "user32" (ByVal hwnd 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 Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long

Private Sub FillChild(hWndParent As Long)
Dim hWndChild As Long
Dim szCaption As String
Dim buffer As String
Dim i As Long

hWndChild = GetWindow(hWndParent, GW_CHILD)
If (hWndChild = 0) Then Exit Sub
hWndChild = GetWindow(hWndChild, GW_HWNDFIRST)
If hWndChild = 0 Then Exit Sub

While (hWndChild <> 0)
szCaption = String$(255, 0)
GetClassName hWndChild, szCaption, 250
szCaption = Left$(szCaption, InStr(szCaption, String$(1, 0)) - 1)
buffer = CStr(hWndChild) & "--" & szCaption
i = GetWindowTextLength(hWndChild)
szCaption = String$(255, 0)
GetWindowText hWndChild, szCaption, 250
szCaption = Left$(szCaption, i)
buffer = buffer & "--" & szCaption

List1.AddItem buffer
FillChild hWndChild
hWndChild = GetWindow(hWndChild, GW_HWNDNEXT)
Wend
End Sub

Private Sub GetChildWindow(hwnd As Long)
Dim szCaption As String
Dim buffer As String

Dim i As Long

List1.Clear
szCaption = String$(255, 0)
GetClassName hwnd, szCaption, 250
szCaption = Left$(szCaption, InStr(szCaption, String$(1, 0)) - 1)

buffer = CStr(hwnd)
buffer = buffer & "--" & szCaption
i = GetWindowTextLength(hwnd)
szCaption = String$(255, 0)
GetWindowText hwnd, szCaption, 250
szCaption = Left$(szCaption, i)
buffer = buffer & "--" & szCaption
List1.AddItem buffer
FillChild hwnd
End Sub

调用方法
GetChildWindow hwnd'hwnd是指定的窗口句柄

结果以

窗体句柄--窗体类名称--窗体Text

形式列在列表框List1中
匿名用户
2015-08-09
展开全部
遍历窗口所有子窗体句柄,参考如下:
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 String '当前的类名及标题名

Call CopyMemory(tClsInfo, ByVal lParam, Len(tClsInfo))

sBuffer1 = String(64, Chr$(0))
sBuffer2 = String(64, Chr$(0))
sBuffer1 = Left$(sBuffer1, GetClassName(hwnd, sBuffer1, 63))
sBuffer2 = Left$(sBuffer2, GetWindowText(hwnd, sBuffer2, 63))

Call CopyMemory(ByVal VarPtrArray(bBuffer1), tClsInfo.pSAName, 4)
Call CopyMemory(ByVal VarPtrArray(bBuffer2), tClsInfo.pSACaption, 4)
sTarName = bBuffer1
sTarCaption = bBuffer2
Call CopyMemory(ByVal VarPtrArray(bBuffer1), 0&, 4)
Call CopyMemory(ByVal VarPtrArray(bBuffer2), 0&, 4)

If sTarCaption = "" And sBuffer1 = sTarName _
Or sBuffer1 = sTarName And sBuffer2 = sTarCaption Then
tClsInfo.lHandle = hwnd
Call CopyMemory(ByVal lParam, tClsInfo, Len(tClsInfo))
EnumChildProc = False
Else
EnumChildProc = True
End If
End Function
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
8989280
2009-04-14
知道答主
回答量:31
采纳率:0%
帮助的人:0
展开全部
看看连接打印机机的电脑防火墙是不是打开了,GOST来宾账号必须要开,那电脑重装过系统你也用不了
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式