在窗体上中放置一个Command1按钮,点击改按钮即可找到并关闭Internet Explorer的窗口
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, lParam As Any) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Long) As LongConst SW_SHOWNORMAL = 1
Const WM_CLOSE = &H10
Const gcClassnameMSWord = "OpusApp"
Const gcClassnameMSExcel = "XLMAIN"
Const gcClassnameMSIExplorer = "IEFrame"
Const gcClassnameMSVBasic = "wndclass_desked_gsk"
Const gcClassnameNotePad = "Notepad"
Const gcClassnameMyVBApp = "ThunderForm"Private Sub Command1_Click()
   'KPD-Team 1998
    'URL: http://www.allapi.net/
    'E-Mail: [email protected]
    Dim WinWnd As Long, Ret As String, RetVal As Long, lpClassName As String
    'Search the window
   WinWnd = 0
    WinWnd = FindWindow(gcClassnameMSIExplorer, vbNullString)
    Do While WinWnd <> 0
      PostMessage WinWnd, WM_CLOSE, 0&, 0&
     WinWnd = 0
      WinWnd = FindWindow(gcClassnameMSIExplorer, vbNullString)
    Loop
End Sub