加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

VB 获取指定类型的所有窗口标题

(2012-02-11 20:48:57)
标签:

it

Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function GetForegroundWindow Lib "user32" () As Long
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd 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 Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As String) As Long
Private Const GW_CHILD = 5
Private Const GW_HWNDNEXT = 2

 

Public Function GetHandle() As Long
    Dim tmp As String
    Dim hwnd As Long, Nhwnd As Long
    Dim strTitle As String * 255     '用来存储窗口的标题
   
    '取得桌面窗口
    hwnd = GetDesktopWindow()
    '取得桌面窗口的第一个子窗口
    hwnd = GetWindow(hwnd, GW_CHILD)
    '通过循环来枚举所有的窗口
    Do While hwnd <> 0
        '取得下一个窗口的标题,并写入到列表框中
        GetWindowText hwnd, strTitle, Len(strTitle)
        '排除第一个字符为空的窗口标题
        If Left(strTitle, 1) <> vbNullChar Then
            '取得记事本所有窗口句柄
            Nhwnd = FindWindow("Notepad", strTitle)
            '取得所有 记事本 窗口标题
            If Nhwnd <> 0 Then
                '取得记事本所有窗口标题
                GetWindowText Nhwnd, strTitle, Len(strTitle)
                tmp = Left(strTitle, InStr(1, strTitle, vbNullChar) - 1)
                Debug.Print tmp
            End If
        End If
        '取得下个窗口句柄
        hwnd = GetWindow(hwnd, GW_HWNDNEXT)
    Loop
End Function

Private Sub Form_Load()
    Call GetHandle
    End
End Sub

 

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有