'创建一个列表框和一个按钮
'API函数定义
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 ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
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
Const GW_HWNDFIRST = 0
Const GW_HWNDNEXT = 2
Private Sub Command1_Click()
Dim s As Long
Dim a As String
a = Space(255)
s = GetWindow(Mehwnd, GW_HWNDFIRST) '获得句柄
GetWindowText s, a, 255 '获得标题
Dim ab As String 255
GetClassName s, ab, 255 '获得类名
Dim ClassName As String
ClassName = StripTerFlag(ab) 'StripTerFlag是一个自定义函数,后面有代码,用于去处结束符
If UCase(ClassName) = "NOTEPAD" Then
List1AddItem a
List1ItemData(List1ListCount - 1) = s
End If
Do While s
DoEvents
s = GetWindow(s, GW_HWNDNEXT) '获得句柄
GetWindowText s, a, 255 '获得标题
GetClassName s, ab, 255 '获得类名
ClassName = StripTerFlag(ab)
If UCase(ClassName) = "NOTEPAD" Then
List1AddItem a
List1ItemData(List1ListCount - 1) = s
End If
Loop
End Sub
Private Sub List1_Click()
MsgBox List1ItemData(List1ListIndex) '单击列表框获得句柄
End Sub
使用EnumWindows和EnumChildWindows函数以及相对的回调函数EnumWindowsProc和EnumChildWindowsProc获取所有顶层窗口以及它们的子窗口(有些窗口做了特殊处理,比如QQ是不能通过这个方法获得的)!
这个语句是获得鼠标指向的窗口句柄用的,后台获取句柄可以用查找窗口句柄命令,列:
Call RunApp("notepadexe")'打开一个记事本
Delay 1500
//下面这句是查找窗口类名("Notepad")或者标题(0),返回找到的句柄Hwnd
Hwnd = PluginWindowFind("Notepad", 0)
MsgBox "查找到的父窗口句柄为:"& Hwnd
以上就是关于vb如何获取某程序的全部句柄全部的内容,包括:vb如何获取某程序的全部句柄、Windows服务怎么获取窗口句柄、按键精灵窗口重启如何再次获取句柄等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)