7,763
社区成员
发帖
与我相关
我的任务
分享
If InStr(1, WindowCaption, Form1.TEXT1.TEXT) > 0 Then
If InStr(1, WindowCaption, TEXT1.TEXT) > 0 Then
'标准模块
Option Explicit
'Private Declare Function GetClassName Lib "user32.dll" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
'Public Declare Function EnumChildWindows Lib "user32.dll" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Boolean
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 Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByRef lParam As Any) As Long
Private Const WM_CLOSE As Long = &H10&
Public Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean
Dim WindowCaption As String, LengthCaption As Long, WindowClassName As String * 256
LengthCaption = GetWindowTextLength(hwnd)
WindowCaption = Space(LengthCaption)
Call GetWindowText(hwnd, WindowCaption, LengthCaption + 1)
'Call GetClassName(hwnd, WindowClassName, 256)
'WindowClassName = Left(WindowClassName, InStr(WindowClassName, Chr(0)) - 1)
If InStr(1, WindowCaption, "窗体的标题") > 0 Then
SendMessage hwnd,WM_CLOSE,0&,0& '关闭指定窗体标题的窗体
End If
EnumWindowsProc = True
End Function
'窗体Form1代码
Option Explicit
'窗体上添加一个命令按钮Command1
Private Sub Command1_Click()
EnumWindows AddressOf EnumWindowsProc, ByVal 0&
End Sub