快捷导航 上传作品

[c++] vb获得 所有窗口句柄 和 标题

[复制链接]
梅雷工具箱发表于 2015-6-25 13:21:11 | 显示全部楼层 |阅读模式

'vb获得 所有窗口句柄 和 标题
'创建一个 List1 控件
'输入以下代码
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 GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Private Const GW_HWNDNEXT = 2

Private Sub Form_Load()
Dim hwnda As Long
Dim hwnd As Long
Dim l As Long
Dim s As String

hwnd = GetForegroundWindow()



   While hwnd <> 0
   l = GetWindowTextLength(hwnd)
   s = String(l + 1, Chr(0))
   GetWindowText hwnd, s, l + 1

   hwnd = GetWindow(hwnd, GW_HWNDNEXT)

   List1.AddItem "句柄:" & hwnd & " - " & "窗口标题:" & s

   Wend
   
   
   
End Sub
就上UG网淘宝直营店
回复

使用道具 评分 举报

您需要登录后才可以回帖 登录 | 注册UG网

本版积分规则