请问:如何枚举当前打开的窗口名称,指WINDOWS进程
我现在想用API函数枚举出当前WINDOWS里打开的窗口,然后把它们的标题列表出来! Option ExplicitPrivate Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetParent Lib "user32" (ByVal hwnd 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 IsWindowVisible Lib "user32" (ByVal hwnd As Long) As Long
Private Const GW_HWNDNEXT = 2
Private Const GW_CHILD = 5
Private Sub Form_Load()
'使用前在窗体上创建一个ListBox控件,名称为List1
Dim hwnd As Long
hwnd = GetDesktopWindow() '返回桌面的句柄
hwnd = GetWindow(hwnd, GW_CHILD) '返回桌面的第一个子窗口
Dim sWindowText As String
Dim r As Long
Do While hwnd <> 0
If GetParent(hwnd) = 0 Then '顶层窗口
If IsWindowVisible(hwnd) Then '窗口状态是显示的
sWindowText = String(255, Chr(0))
r = GetWindowText(hwnd, sWindowText, 255) '返回窗口的标题
sWindowText = Left(sWindowText, r)
If sWindowText <> "" Then List1.AddItem sWindowText
End If
End If
hwnd = GetWindow(hwnd, GW_HWNDNEXT) '返回下一个窗口
Loop
End Sub efan2000发表于2004-7-16 20:02:00static/image/common/back.gifOption ExplicitPrivate Declare Function GetDesktopWindow Lib \"user32\" () As LongPrivate Declare Function GetWindow Lib \"user32\" (ByVal hwnd As Long, ByVal wCmd As Long) As Lon
<p>efan2000 <br/>对API有比较深的了解</p>
页:
[1]