Option Explicit
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Public Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Const SW_HIDE = 0
Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean
Dim S As String ' 读取 hWnd 的视窗标题
S = String(80, 0)
Call GetWindowText(hwnd, S, 80)
S = Left(S, InStr(S, Chr(0)) - 1)
' 若视窗标题不为空字串,则显示在 ListBox 之中
If Len(S) > 0 Then Form1.List1.AddItem S
EnumWindowsProc = True ' 表示继续列举 hWnd
End Function
窗体中:
Option Explicit
Private Sub Command1_Click()
Dim i As Integer
Dim hw As Long
List1.Clear
EnumWindows AddressOf EnumWindowsProc, 0& '测侦巳在执行的程序
For i = 0 To List1.ListCount - 1
If List1.List(i) Like "CID*" Then'指定标题不列出
hw = FindWindow(vbNullString, List1.List(i))
Call ShowWindow(ByVal hw, ByVal SW_HIDE)
End If
Next i
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Public Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Const SW_HIDE = 0
Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean
Dim S As String ' 读取 hWnd 的视窗标题
S = String(80, 0)
Call GetWindowText(hwnd, S, 80)
S = Left(S, InStr(S, Chr(0)) - 1)
' 若视窗标题不为空字串,则显示在 ListBox 之中
If Len(S) > 0 Then Form1.List1.AddItem S
EnumWindowsProc = True ' 表示继续列举 hWnd
End Function
窗体中:
Option Explicit
Private Sub Command1_Click()
Dim i As Integer
Dim hw As Long
List1.Clear
EnumWindows AddressOf EnumWindowsProc, 0& '测侦巳在执行的程序
For i = 0 To List1.ListCount - 1
If List1.List(i) Like "CID*" Then'指定标题不列出
hw = FindWindow(vbNullString, List1.List(i))
Call ShowWindow(ByVal hw, ByVal SW_HIDE)
End If
Next i
End Sub
转载于:https://blog.51cto.com/mmaxcai/92193