请问下VB如何枚举指定窗口的句柄呢?
请问下VB如何枚举指定窗口的句柄呢?比如顶级窗口内部有3个子句柄,其中一个的句柄类名是ATO:123456-我想通过判断这个ATO:这几个字符判断这个句柄。因为ATO:后...
请问下VB如何枚举指定窗口的句柄呢?比如顶级窗口内部有3个子句柄,其中一个的句柄类名是ATO:123456 - 我想通过判断这个ATO:这几个字符判断这个句柄。因为ATO:后面的123456是会随机改变的,所以枚举内部3个子句柄类名前面的ATO:做判断才可以获取真是的句柄。
窗口结构:窗口内部有3个按钮-其中一个按钮的类名是ATO:123456 -每次打开这个程序这个按钮的类名 ATO:后面的123456数字都会随机改变,如何才可以准确的获取这个按钮的句柄呢?
判断指定窗口标题 -枚举顶级窗口内部的子句柄- 判断类名是否有ATO:字符串 ,如果有就放句柄到变量去。谁可以写个VB的列子,请高手指教谢谢。
为什么不可能啊?枚举 窗口3个按钮句柄
第一个按钮类名 SDO7 第2个按钮类名SOD8 第三个按钮类名 ATO:123456
只要枚举这3个按钮的句柄之后,在一个一个的取出类名来判断不就可以了么? 展开
窗口结构:窗口内部有3个按钮-其中一个按钮的类名是ATO:123456 -每次打开这个程序这个按钮的类名 ATO:后面的123456数字都会随机改变,如何才可以准确的获取这个按钮的句柄呢?
判断指定窗口标题 -枚举顶级窗口内部的子句柄- 判断类名是否有ATO:字符串 ,如果有就放句柄到变量去。谁可以写个VB的列子,请高手指教谢谢。
为什么不可能啊?枚举 窗口3个按钮句柄
第一个按钮类名 SDO7 第2个按钮类名SOD8 第三个按钮类名 ATO:123456
只要枚举这3个按钮的句柄之后,在一个一个的取出类名来判断不就可以了么? 展开
5个回答
展开全部
以下在Form1,需要一个text控件,设定MultiLine为True
ClassNames(i)返回的是类名,所以你可以用instr函数查找你需要的ATO.....
另外这个示例是以窗口标题查找的,比如我这是打开“我的电脑”就可以运行下面示例
最后说明这个是网友Seneal的,我只是引用和解释
--------------------------------------
Private Sub Form_Load()
GetChildWindow FindWindow(vbNullString, Trim("我的电脑"))
j = N - 1
If j Then
For i = 0 To j
Text1.Text = Text1.Text & hWnds(i) '句柄
Text1.Text = Text1.Text & "|"
Text1.Text = Text1.Text & Trim(sCaptions(i)) '标题
Text1.Text = Text1.Text & "|"
Text1.Text = Text1.Text & ClassNames(i) '类名
Text1.Text = Text1.Text & vbCrLf
Next
End If
End Sub
--------------------------------------
以下在模块里
————————————————————
Public Const GW_CHILD = 5
Public Const GW_HWNDFIRST = 0
Public Const GW_HWNDNEXT = 2
Public Const WM_GETTEXT = &HD
Public Const WM_SETTEXT = &HC
Public Const WM_ENABLE = &HA
Public Const WM_DESTROY = &H2
Public Const WM_KEYDOWN = &H100
Public Const WM_KEYUP = &H101
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Public Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Public Declare Function IsWindow Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Public Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public N As Integer
Public hWnds(0 To 255) As Long
Public sCaptions(0 To 255) As String * 255
Public ClassNames(0 To 255) As String * 255
Private Sub FillChild(hWndParent As Long)
Dim hWndChild 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)
N = N + 1
hWnds(N) = hWndChild
GetClassName hWndChild, ClassNames(N), 255
GetWindowText hWndChild, sCaptions(N), 255
FillChild hWndChild
hWndChild = GetWindow(hWndChild, GW_HWNDNEXT)
Wend
End Sub
Public Sub GetChildWindow(hwnd As Long)
Erase hWnds
Erase ClassNames
Erase sCaptions
N = 0
hWnds(N) = hwnd
GetClassName hwnd, ClassNames(N), 255
GetWindowText hwnd, sCaptions(N), 255
FillChild hwnd
End Sub
ClassNames(i)返回的是类名,所以你可以用instr函数查找你需要的ATO.....
另外这个示例是以窗口标题查找的,比如我这是打开“我的电脑”就可以运行下面示例
最后说明这个是网友Seneal的,我只是引用和解释
--------------------------------------
Private Sub Form_Load()
GetChildWindow FindWindow(vbNullString, Trim("我的电脑"))
j = N - 1
If j Then
For i = 0 To j
Text1.Text = Text1.Text & hWnds(i) '句柄
Text1.Text = Text1.Text & "|"
Text1.Text = Text1.Text & Trim(sCaptions(i)) '标题
Text1.Text = Text1.Text & "|"
Text1.Text = Text1.Text & ClassNames(i) '类名
Text1.Text = Text1.Text & vbCrLf
Next
End If
End Sub
--------------------------------------
以下在模块里
————————————————————
Public Const GW_CHILD = 5
Public Const GW_HWNDFIRST = 0
Public Const GW_HWNDNEXT = 2
Public Const WM_GETTEXT = &HD
Public Const WM_SETTEXT = &HC
Public Const WM_ENABLE = &HA
Public Const WM_DESTROY = &H2
Public Const WM_KEYDOWN = &H100
Public Const WM_KEYUP = &H101
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Public Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Public Declare Function IsWindow Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Public Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public N As Integer
Public hWnds(0 To 255) As Long
Public sCaptions(0 To 255) As String * 255
Public ClassNames(0 To 255) As String * 255
Private Sub FillChild(hWndParent As Long)
Dim hWndChild 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)
N = N + 1
hWnds(N) = hWndChild
GetClassName hWndChild, ClassNames(N), 255
GetWindowText hWndChild, sCaptions(N), 255
FillChild hWndChild
hWndChild = GetWindow(hWndChild, GW_HWNDNEXT)
Wend
End Sub
Public Sub GetChildWindow(hwnd As Long)
Erase hWnds
Erase ClassNames
Erase sCaptions
N = 0
hWnds(N) = hwnd
GetClassName hwnd, ClassNames(N), 255
GetWindowText hwnd, sCaptions(N), 255
FillChild hwnd
End Sub
追问
这个只可以获取标题和类名吧,但是不能准确获取我那个按钮的句柄啊。
追答
看你的意思,你试了吗?
Text1.Text = Text1.Text & hWnds(i) '句柄
这个不是句柄?
展开全部
类名是控件类型的名字,不可能是变化的。类名不固定,无法得到句柄,标题不固定类名固定还有可能。
追问
第一个按钮类名 SDO7 第2个按钮类名SOD8 第三个按钮类名 ATO:123456
只要枚举这3个按钮的句柄之后,在一个一个的取出类名来判断不就可以了么?
追答
Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
可以枚举句柄,搜索 “Declare Function EnumWindows”
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
BOOL EnumChildWindows( HWND hWndParent,
WNDENUMPROC lpEnumFunc,
LPARAM lParam
);
WNDENUMPROC lpEnumFunc,
LPARAM lParam
);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
是什么软件中的按钮
追问
只是个普通的软件按钮。
追答
不说帮不上
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Text1_Click(Index As Integer)
Label1.Caption = Text1(Index).Text
End Sub
Label1.Caption = Text1(Index).Text
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询