Option Explicit
Private Declare Function GetForegroundWindow Lib "user32" () 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 IsWindow Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long
Const SW_HIDE = 0
Const SW_SHOW = 5
Dim winName As String
Dim hWindow As Long
Private Sub Timer1_Timer()
winName = String(255, 0)
hWindow = GetForegroundWindow()
Call GetWindowText(hWindow, winName, 255)
winName = Left(winName, InStr(winName, Chr(0)) - 1)
If winName = "Form1" Then '引号里的Form1换成你要的窗口名
If IsWindow(hWindow) = 0 Then Exit Sub
Call ShowWindow(hWindow, SW_HIDE)
End If
End Sub