vb 获取可见窗口句柄到list

来源:百度知道 编辑:UC知道 时间:2024/09/24 00:46:12
Option Explicit

Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long

Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean
Dim S As String

S = String(80, 0)
Call GetWindowText(hwnd, S, 80)
S = Left(S, InStr(S, Chr(0)) - 1)

If Len(S) > 0 Then Form1.List1.AddItem S

EnumWindowsProc = True
End Function

窗体中加一按钮和一列表框,直接Copy即可运行:

Private Sub Command1_Click()
List1.Clear
EnumWindows AddressOf EnumWindowsProc, 0&
End Sub
这个显示出来的东西很多,我只想要 任务栏里有显示的啊
只有10分了= =

If IsWindowVisible(hwnd) Then
Form1.List1.AddItem S
End If
'API函数ISWindowVisibie判断由hwnd标识的窗体是否存放在于屏幕上。如果指定窗口存放于屏幕上,则将该窗口的标题添加到列表框中