VB 枚举窗口-获取游戏发送窗口句柄的问题

我已经成功枚举aa.exe游戏的所有句柄显示在List1中,我想要的句柄也在里面但是我想得到我要的句柄如何写代码?那个句柄只知道类名叫(Edit)没窗口名的,我有个构思,... 我已经成功枚举aa.exe游戏的所有句柄显示在List1中, 我想要的句柄也在里面 但是我想得到我要的句柄如何写代码? 那个句柄只知道类名叫(Edit) 没窗口名的,
我有个构思,不知道有没有这样的代码。
也就是把List1里面的所有句柄比较,假如符合类名为Edit的即保存到数组A
然后数组A就是我要发送消息的句柄。 请给出代码谢谢了!
(上面的问题是想达到自动获取游戏里只有类名 没标题的子窗体句柄,如有高招 请帮帮忙给代码 谢谢了)
展开
 我来答
远风的梦想家
2010-07-11 · TA获得超过2550个赞
知道大有可为答主
回答量:1389
采纳率:0%
帮助的人:0
展开全部
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
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 GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetDesktopWindow Lib "user32" () 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 Const GW_HWNDFIRST = 0
Private Const GW_HWNDNEXT = 2
Private Const GW_CHILD = 5

Dim a() As Long '定义数组
Private Sub Command1_Click()
Dim hwnd As Long
Dim s As String, t As String

List1.Clear
hwnd = GetDesktopWindow()

hwnd = GetWindow(hwnd, GW_CHILD Or GW_HWNDFIRST)

While hwnd <> 0
hwnd = GetWindow(hwnd, GW_HWNDNEXT)
s = String(256, Chr(0))
GetClassName hwnd, s, 255
s = Replace(s, Chr(0), "")
If s = "IEFrame" Then '要匹配的窗口类名
EnumAllHandles hwnd '枚举所有子控件/窗口
Exit Sub
End If
Wend
If List1.ListCount > 0 Then
ReDim a(0 To List1.ListCount - 1) As Long
Dim i As Integer
For i = 0 To UBound(a)
a(i) = List1.List(i)
Next i
End If
End Sub

Private Sub Form_Load()
Command1.Caption = "查找"
End Sub

Private Sub EnumAllHandles(ByVal hwnd As Long)
Dim hn As Long
Dim firsthd As Long
Dim s As String, t As String
firsthd = GetWindow(hwnd, GW_CHILD)
firsthd = GetWindow(firsthd, GW_HWNDFIRST)
hn = firsthd
Do While hn <> 0
s = String(256, Chr(0))
GetClassName hn, s, 255
s = Replace(s, Chr(0), "")
t = String(256, Chr(0))
GetWindowText hn, t, 255
t = Replace(t, Chr(0), "")
If t = "" Then '符合条件就加入到list里
List1.AddItem "句柄:" & hn & " 父句柄:" & hwnd & " 类名:" & s & "标题:" & t & vbCrLf
End If
EnumAllHandles hn '递归查找,不放过子控件

hn = GetWindow(hn, GW_HWNDNEXT)
If hn = firsthd Then Exit Do
Loop
End Sub

'有问题百度hi我
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式