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,"新建 文本文档.txt - 记事本") '获得指定窗体标题的窗体的句柄
If hwnd = 0 Then
MsgBox "未找到窗口"
Else
result = PostMessage(hwnd,WM_CLOSE,0&,0&)'向目标程序发送消息
If result = 0 Then
MsgBox "关闭窗口失败!"
Else
MsgBox "成功关闭窗口!"
End If
End If
End Sub