欢迎大家访问我的网站!

VB隐藏关键词窗口

思博2023-08-10 22:01:25290编程开发
 Option Explicit
Private 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 GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Const SW_HIDE = 0
Private Const SW_SHOW = 1
Private Const WM_CLOSE = &H10
Private Const GW_CHILD = 5
Private Const GW_HWNDNEXT = 2
Private Handle As Long
'监视包含文字的数量。
Dim CloseCX(1) As String
Private Sub Command1_Click()
'监视包含以下文字的窗口。
CloseCX(0) = "c:\"
CloseCX(1) = Text1.Text
Call GetAllWindows
End Sub
 
'该函数用来取得系统中所有打开的窗口
Public Function GetAllWindows() As Long
    '用来保存窗口的句柄
   Dim hwnd As Long
   Dim Fx As Integer
   '取得桌面窗口
   hwnd = GetDesktopWindow()
   '取得桌面窗口的第一个子窗口
   hwnd = GetWindow(hwnd, GW_CHILD)
     
   Dim strTitle As String * 255     '用来存储窗口的标题
   '通过循环来枚举所有的窗口
   Do While hwnd <> 0
        '取得下一个窗口的标题
        GetWindowText hwnd, strTitle, Len(strTitle)
        If Left$(strTitle, 1) <> vbNullChar Then
       
            For Fx = 0 To UBound(CloseCX, 1)
                If InStr(Left$(strTitle, InStr(1, strTitle, vbNullChar)), CloseCX(Fx)) > 0 Then '检查是否包含定义的字符
                    Handle = FindWindow(vbNullString, Left$(strTitle, InStr(1, strTitle, vbNullChar)))
                  ShowWindow Handle, SW_HIDE '如果包含 发送关闭命令.
                End If
            Next
        End If
        '调用GetWindow函数,来取得下一个窗口
        hwnd = GetWindow(hwnd, GW_HWNDNEXT)
   Loop
End Function
Public Function GetAllWindowsSHOW() As Long
    '用来保存窗口的句柄
   Dim hwnd As Long
   Dim Fx As Integer
   '取得桌面窗口
   hwnd = GetDesktopWindow()
   '取得桌面窗口的第一个子窗口
   hwnd = GetWindow(hwnd, GW_CHILD)
     
   Dim strTitle As String * 255     '用来存储窗口的标题
   '通过循环来枚举所有的窗口
   Do While hwnd <> 0
        '取得下一个窗口的标题
        GetWindowText hwnd, strTitle, Len(strTitle)
        If Left$(strTitle, 1) <> vbNullChar Then
       
            For Fx = 0 To UBound(CloseCX, 1)
                If InStr(Left$(strTitle, InStr(1, strTitle, vbNullChar)), CloseCX(Fx)) > 0 Then '检查是否包含定义的字符
                    Handle = FindWindow(vbNullString, Left$(strTitle, InStr(1, strTitle, vbNullChar)))
                  ShowWindow Handle, SW_SHOW '如果包含 发送关闭命令.
                End If
            Next
        End If
        '调用GetWindow函数,来取得下一个窗口
        hwnd = GetWindow(hwnd, GW_HWNDNEXT)
   Loop
End Function
Private Sub Command2_Click()
CloseCX(0) = "c:\"
CloseCX(1) = Text1.Text
Call GetAllWindowsSHOW
End Sub

Private Sub Command3_Click()
End
End Sub


转载声明:本站发布文章及版权归原作者所有,转载本站文章请注明文章来源!

本文链接:http://lxkj.vip/?id=94

网友评论