VB中如何使用GetNextWindow函数枚举所有窗口
用GetNextWindow函数枚举所有窗口在枚举过程中,又该如何用GetWindowText函数得到窗口标题?高手们能不能帮帮忙?略给几道程序出来......
用GetNextWindow 函数枚举所有窗口
在枚举过程中,又该如何用GetWindowText函数得到窗口标题?高手们能不能帮帮忙?略给几道程序出来... 展开
在枚举过程中,又该如何用GetWindowText函数得到窗口标题?高手们能不能帮帮忙?略给几道程序出来... 展开
1个回答
展开全部
1.定义一个模块, 内容为:
Option Explicit
Public Declare Function GetNextWindow Lib "user32" Alias "GetWindow" (ByVal hwnd As Long, ByVal wFlag As Long) As Long
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 FindWindowa Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function GetForegroundWindow Lib "user32" () As Long
2. 给窗口加一个按钮, 在按钮的click事件里写以下内容:
Option Explicit
Private Sub Command1_Click()
Dim hwnd As Long
hwnd = GetForegroundWindow ' FindWindowa("Notepad", "新建 文本文档.txt - 记事本")
Dim str1 As String, len1 As Long
str1 = Space(255) '定义接收字串.
GetWindowText hwnd, str1, 1024
Do While hwnd <> 0
hwnd = GetNextWindow(hwnd, 2) '只有2才表示找下一个窗口
len1 = GetWindowText(hwnd, str1, Len(str1))
If (InStr(1, str1, "记事", 1) > 0) Then
MsgBox "你要的窗口找到了, 它是:" + str1
Exit Sub '这一句看情况修改
End If
Loop
MsgBox "很遣憾, 没有你要找的窗口"
End Sub
3. 测试, 一定会通过.
Option Explicit
Public Declare Function GetNextWindow Lib "user32" Alias "GetWindow" (ByVal hwnd As Long, ByVal wFlag As Long) As Long
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 FindWindowa Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function GetForegroundWindow Lib "user32" () As Long
2. 给窗口加一个按钮, 在按钮的click事件里写以下内容:
Option Explicit
Private Sub Command1_Click()
Dim hwnd As Long
hwnd = GetForegroundWindow ' FindWindowa("Notepad", "新建 文本文档.txt - 记事本")
Dim str1 As String, len1 As Long
str1 = Space(255) '定义接收字串.
GetWindowText hwnd, str1, 1024
Do While hwnd <> 0
hwnd = GetNextWindow(hwnd, 2) '只有2才表示找下一个窗口
len1 = GetWindowText(hwnd, str1, Len(str1))
If (InStr(1, str1, "记事", 1) > 0) Then
MsgBox "你要的窗口找到了, 它是:" + str1
Exit Sub '这一句看情况修改
End If
Loop
MsgBox "很遣憾, 没有你要找的窗口"
End Sub
3. 测试, 一定会通过.
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询