'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
|