vb中 如何获得窗体中所有控件的句柄?

 我来答
心耆R缩1痛
2013-10-29 · TA获得超过106个赞
知道答主
回答量:180
采纳率:33%
帮助的人:59.8万
展开全部
OptionExplicitPrivateDeclareFunctionFindWindowLibuser32AliasFindWindowA(ByVallpClassNameAsString,ByVallpWindowNameAsString)AsLongPrivateDeclareFunctionGetWindowTextLibuser32AliasGetWindowTextA(ByValhwndAsLong,ByVallpStringAsString,ByValcchAsLong)AsLongPrivateDeclareFunctionGetWindowLibuser32(ByValhwndAsLong,ByValwCmdAsLong)AsLongPrivateDeclareFunctionGetDesktopWindowLibuser32()AsLongPrivateDeclareFunctionGetClassNameLibuser32AliasGetClassNameA(ByValhwndAsLong,ByVallpClassNameAsString,ByValnMaxCountAsLong)AsLongPrivateConstGW_HWNDFIRST=0PrivateConstGW_HWNDNEXT=2PrivateConstGW_CHILD=5PrivateSubCommand1_Click()CallList1_ClickEndSubPrivateSubCommand2_Click()DimhwndAsLongDimsAsString,tAsStringList1.Clearhwnd=GetDesktopWindow()s=String(256,Chr(0))GetClassNamehwnd,s,255s=Replace(s,Chr(0),)t=String(256,Chr(0))GetWindowTexthwnd,t,255t=Replace(t,Chr(0),)List1.AddItem桌面:&hwnd&类名:&s&标题:&t&vbCrLfhwnd=GetWindow(hwnd,GW_CHILDOrGW_HWNDFIRST)s=String(256,Chr(0))GetClassNamehwnd,s,255s=Replace(s,Chr(0),)t=String(256,Chr(0))GetWindowTexthwnd,t,255t=Replace(t,Chr(0),)List1.AddItem窗口:&hwnd&类名:&s&标题:&t&vbCrLfWhilehwnd<0hwnd=GetWindow(hwnd,GW_HWNDNEXT)s=String(256,Chr(0))GetClassNamehwnd,s,255s=Replace(s,Chr(0),)t=String(256,Chr(0))GetWindowTexthwnd,t,255t=Replace(t,Chr(0),)List1.AddItem窗口:&hwnd&类名:&s&标题:&t&vbCrLfWendEndSubPrivateSubForm_Load()Command1.Caption=获取所有控件Command2.Caption=遍历所有窗体EndSubPrivateSubEnumAllHandles(ByValhwndAsLong)DimhnAsLongDimfirsthdAsLongDimsAsString,tAsStringfirsthd=GetWindow(hwnd,GW_CHILD)firsthd=GetWindow(firsthd,GW_HWNDFIRST)hn=firsthdDoWhilehn<0s=String(256,Chr(0))GetClassNamehn,s,255s=Replace(s,Chr(0),)t=String(256,Chr(0))GetWindowTexthn,t,255t=Replace(t,Chr(0),)Text1.Text=Text1.Text&句柄:&hn&父句柄:&hwnd&类名:&s&标题:&t&vbCrLfTreeView1.Nodes.Addk&hwnd,tvwChild,k&hn,句柄:&hn&类名:&s&标题:&tEnumAllHandleshnhn=GetWindow(hn,GW_HWNDNEXT)Ifhn=firsthdThenExitDoLoopEndSubPrivateSubList1_Click()IfList1.ListIndex=-1ThenExitSubTreeView1.Nodes.ClearTreeView1.Nodes.Add,,k&Trim(Str(Val(Mid(List1.Text,4)))),List1.TextText1.Text=EnumAllHandlesVal(Mid(List1.Text,4))TreeView1.Nodes(k&Trim(Str(Val(Mid(List1.Text,4))))).Expanded=TrueEndSub'添加两个按钮一个文本框一个列表框和一个树形图
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式