1,488
社区成员
发帖
与我相关
我的任务
分享Option Explicit
Private Sub Command2_Click()
Dim l As Boolean
Text1.Text = ""
l = EnumWindows(AddressOf EnumWindowsProc, ByVal 0&)
'Text1.Text = xx
End SubOption Explicit
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
Public Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
Dim RetVal As Long
Dim CaptionLength As Long
Dim WindowCaption As String
Dim a As String
a = "123"
CaptionLength = GetWindowTextLength(hwnd) '取得顶级窗口标题长度
WindowCaption = Space(CaptionLength) '设置窗口标题长度
RetVal = GetWindowText(hwnd, WindowCaption, CaptionLength + 1)
'WindowCaption = Left(WindowCaption, InStr(WindowCaption, Chr(0)) - 1) '去掉尾部空格
Debug.Print WindowCaption
If InStr(WindowCaption, a) > 0 Then
Form1.Text1.Text = Form1.Text1.Text & WindowCaption & vbCrLf
Else
'''''''''''''''''
End If
EnumWindowsProc = 1 'True
End FunctionFunction EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
Dim RetVal As Long
Dim dd As String * 255
Dim a As String
a = "123"
RetVal = GetWindowText(hwnd, dd, 255)
If 0<> InStr(dd, a) Then
form1.text1.text = form1.text1.text & vbcrlf & dd
Else
End If
EnumWindowsProc=1
End Function