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,tAsStringList1Clearhwnd=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),)List1AddItem桌面:&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),)List1AddItem窗口:&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),)List1AddItem窗口:&hwnd&类名:&s&标题:&t&vbCrLfWendEndSubPrivateSubForm_Load()Command1Caption=获取所有控件Command2Caption=遍历所有窗体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),)Text1Text=Text1Text&句柄:&hn&父句柄:&hwnd&类名:&s&标题:&t&vbCrLfTreeView1NodesAddk&hwnd,tvwChild,k&hn,句柄:&hn&类名:&s&标题:&tEnumAllHandleshnhn=GetWindow(hn,GW_HWNDNEXT)Ifhn=firsthdThenExitDoLoopEndSubPrivateSubList1_Click()IfList1ListIndex=-1ThenExitSubTreeView1NodesClearTreeView1NodesAdd,,k&Trim(Str(Val(Mid(List1Text,4)))),List1TextText1Text=EnumAllHandlesVal(Mid(List1Text,4))TreeView1Nodes(k&Trim(Str(Val(Mid(List1Text,4)))))Expanded=TrueEndSub'添加两个按钮一个文本框一个列表框和一个树形图
------解决方案--------------------------------------------------------Handle()功能 得到PowerBuilder窗口型对象的句柄 使用该函数可以得到应用对象 窗口或控件的句柄 但不能得到绘图对象的句柄
以上就是关于vb中 如何获得窗体中所有控件的句柄全部的内容,包括:vb中 如何获得窗体中所有控件的句柄、请教怎么获取窗口中的控件对象、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)