使用API函数。先通过FindWindow得到窗口的句柄,然后对窗口发送关闭消息。
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
Const WM_CLOSE = &H10
Private Sub Command1_Click()
Dim hwnd, result As Long
hwnd = FindWindow(vbNullString, "迅雷5") '查找窗体标题
If hwnd = 0 Then
MsgBox "未找到窗口"
Else
result = PostMessage(hwnd, WM_CLOSE, 0&, 0&)
If result = 0 Then
MsgBox "关闭窗口失败"
Else
MsgBox "关闭OK"
End If
End If
End Sub
责任编辑:cyth