Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Public 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 Public Const WM_CLOSE = &H10 Private Sub Command1_Click() Dim winHwnd As Long Dim RetVal As LongwinHwnd = FindWindow(vbNullString, "程序名") Debug.Print winHwnd If winHwnd <> 0 Then RetVal = PostMessage(winHwnd, WM_CLsOSE, 0&, 0&) If RetVal = 0 Then MsgBox "error" End If Else MsgBox "meidakaichengxu" End IfEnd Sub
hwnd=FindWindow("标题",0)CloseWindow(hwnd)
Public 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
Public Const WM_CLOSE = &H10
Private Sub Command1_Click()
Dim winHwnd As Long
Dim RetVal As LongwinHwnd = FindWindow(vbNullString, "程序名")
Debug.Print winHwnd
If winHwnd <> 0 Then
RetVal = PostMessage(winHwnd, WM_CLsOSE, 0&, 0&)
If RetVal = 0 Then
MsgBox "error"
End If
Else
MsgBox "meidakaichengxu"
End IfEnd Sub
只有漂走的云的代码是很完整的,我试过了,问题的关键是给wm_close赋值和使用postmessage,谢谢!