我用EnumWindows枚举当前所有已打开窗口标题栏名称为何得不到IE和QQ的窗口标题呢?
以下代码可以枚举当前系统所有已打开窗口的标题栏名称。可经过测试发现始终枚举不到IE和QQ的窗口标题,甚至连记事本写字板的窗口标题都枚举不到。貌似有好多窗口都枚举不到,能枚...
以下代码可以枚举当前系统所有已打开窗口的标题栏名称。可经过测试发现始终枚举不到 IE 和 QQ 的窗口标题,甚至连记事本写字板的窗口标题都枚举不到。貌似有好多窗口都枚举不到,能枚举到的是一大堆在后台运行的程序窗口,可这些对我没用啊。请问以下代码有什么不对的地方吗?EnumWindows不是可以枚举到屏幕上所有的顶层窗口吗,可我的代码为什么枚举不到呢?
Private Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) 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 Function EnumWndProc(ByVal lhWnd As Long, ByVal lParam As Long) As Long
Dim strWndTextBuff As String * 255&
Dim strWndHeading As String
Call GetWindowText(lhWnd, strWndTextBuff, 255&)
If (InStr(strWndTextBuff, Chr(0&)) > 0&) Then
strWndHeading = Left(strWndTextBuff, InStr(strWndTextBuff, Chr(0&)) - 1&)
Debug.Print strWndHeading
End If
EnumWndProc = True
End Function
Call EnumWindows(AddressOf EnumWndProc, 0&)
现在我的问题终于解决了
这个可以获得第一个IE窗口内所有页面选项卡的标题:
Private Function EnumWndProc(ByVal hWnd As Long, ByVal lParam As Long) As Long
Dim lnghWnd As Long
Dim strWndClassBuff As String * 255
Dim strWndTextBuff As String * 255
Dim strWndHeading As String
Call GetClassName(hWnd, strWndClassBuff, Len(strWndClassBuff))
If (InStr(strWndClassBuff, vbNullChar) > 0&) Then
If Left(strWndClassBuff, InStr(strWndClassBuff, vbNullChar) - 1&) = "TabWindowClass" Then
strWndHeading = Left(strWndTextBuff, GetWindowText(hWnd, strWndTextBuff, Len(strWndTextBuff)))
Debug.Print strWndHeading
End If
End If
EnumWndProc = True
End Function
Dim lnghWnd As Long
lnghWnd = FindWindow("IEFrame", vbNullString)
Call EnumChildWindows(lnghWnd, AddressOf EnumWndProc, 0&)
而这个示例是使用GetWindow获得所有的窗口标题: http://fy5388.blog.163.com/blog/static/5649953720091127115931159/ 展开
Private Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) 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 Function EnumWndProc(ByVal lhWnd As Long, ByVal lParam As Long) As Long
Dim strWndTextBuff As String * 255&
Dim strWndHeading As String
Call GetWindowText(lhWnd, strWndTextBuff, 255&)
If (InStr(strWndTextBuff, Chr(0&)) > 0&) Then
strWndHeading = Left(strWndTextBuff, InStr(strWndTextBuff, Chr(0&)) - 1&)
Debug.Print strWndHeading
End If
EnumWndProc = True
End Function
Call EnumWindows(AddressOf EnumWndProc, 0&)
现在我的问题终于解决了
这个可以获得第一个IE窗口内所有页面选项卡的标题:
Private Function EnumWndProc(ByVal hWnd As Long, ByVal lParam As Long) As Long
Dim lnghWnd As Long
Dim strWndClassBuff As String * 255
Dim strWndTextBuff As String * 255
Dim strWndHeading As String
Call GetClassName(hWnd, strWndClassBuff, Len(strWndClassBuff))
If (InStr(strWndClassBuff, vbNullChar) > 0&) Then
If Left(strWndClassBuff, InStr(strWndClassBuff, vbNullChar) - 1&) = "TabWindowClass" Then
strWndHeading = Left(strWndTextBuff, GetWindowText(hWnd, strWndTextBuff, Len(strWndTextBuff)))
Debug.Print strWndHeading
End If
End If
EnumWndProc = True
End Function
Dim lnghWnd As Long
lnghWnd = FindWindow("IEFrame", vbNullString)
Call EnumChildWindows(lnghWnd, AddressOf EnumWndProc, 0&)
而这个示例是使用GetWindow获得所有的窗口标题: http://fy5388.blog.163.com/blog/static/5649953720091127115931159/ 展开
4个回答
展开全部
模块代码
Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam 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 Function EnumWndProc(ByVal lhWnd As Long, ByVal lParam As Long) As Long
Dim strWndTextBuff As String * 255&
Dim strWndHeading As String
Call GetWindowText(lhWnd, strWndTextBuff, 255&)
If (InStr(strWndTextBuff, Chr(0&)) > 0&) Then
strWndHeading = Left(strWndTextBuff, InStr(strWndTextBuff, Chr(0&)) - 1&)
Debug.Print strWndHeading
Form1.Text1.Text = strWndHeading
If Form1.Text1.Text = "QQ2010" Then
MsgBox Form1.Text1.Text
End If
End If
EnumWndProc = True
End Function
窗体代码
Private Sub Command1_Click()
EnumWindows AddressOf EnumWndProc, 0&
End Sub
我就是把你的代码复制过去然后加了个测试QQ窗口的代码
Form1.Text1.Text = strWndHeading
If Form1.Text1.Text = "QQ2010" Then
MsgBox Form1.Text1.Text
End If
测试能够遍历到QQ的窗口,不知道你怎么搞的弄不到!
enumwindows能遍历到好几十个窗口,你确定查看了所有print?
Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam 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 Function EnumWndProc(ByVal lhWnd As Long, ByVal lParam As Long) As Long
Dim strWndTextBuff As String * 255&
Dim strWndHeading As String
Call GetWindowText(lhWnd, strWndTextBuff, 255&)
If (InStr(strWndTextBuff, Chr(0&)) > 0&) Then
strWndHeading = Left(strWndTextBuff, InStr(strWndTextBuff, Chr(0&)) - 1&)
Debug.Print strWndHeading
Form1.Text1.Text = strWndHeading
If Form1.Text1.Text = "QQ2010" Then
MsgBox Form1.Text1.Text
End If
End If
EnumWndProc = True
End Function
窗体代码
Private Sub Command1_Click()
EnumWindows AddressOf EnumWndProc, 0&
End Sub
我就是把你的代码复制过去然后加了个测试QQ窗口的代码
Form1.Text1.Text = strWndHeading
If Form1.Text1.Text = "QQ2010" Then
MsgBox Form1.Text1.Text
End If
测试能够遍历到QQ的窗口,不知道你怎么搞的弄不到!
enumwindows能遍历到好几十个窗口,你确定查看了所有print?
展开全部
貌似不完整
枚举窗体的EnumWindows函数
是一个回调函数
需要有一个回调过程
枚举窗体的EnumWindows函数
是一个回调函数
需要有一个回调过程
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
没写完整把
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询