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, ByVal lParam As Long) As LongPrivate Const WM_CLOSE = &H10Private Sub cmdCloseApp_Click() Dim CloseIt As Long CloseIt = FindWindow(vbNullString, "ccc") PostMessage CloseIt, WM_CLOSE, CLng(0), CLng(0) End Sub
2楼的代码测试没问题但是我在a.exe里有这样的代码Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) If UnloadMode = 0 Then If MsgBox("您确定吗", vbOKCancel) Then Unload Me Else Cancel = True End If End If End Sub这样PostMessage 后出来的是对话框,我不希望他出现对话框,希望他直接关闭 有什么办法吗?
Option ExplicitPrivate Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, _ ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Const WM_CLOSE = &H10Private Sub Command1_Click() Dim lngTmp As Long lngTmp = FindWindow(vbNullString, "P1") Call SendMessage(lngTmp, WM_CLOSE, 0, 0) End Sub
用sendmessage , 上面P1改成ccc
一样啊 现在是可以关闭了 但是有另外一个问题 但是我在a.exe里有这样的代码 Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) If UnloadMode = 0 Then If MsgBox("您确定吗", vbOKCancel) Then Unload Me Else Cancel = True End If End If End Sub 这样PostMessage 后出来的是对话框,我不希望他出现对话框,希望他直接关闭 有什么办法吗?
用shell("pskill a.exe"); 其中pskill.exe是一个工具软件
我重复测试过了 会出现对话提示的但是我在a.exe里有这样的代码 Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) If UnloadMode = 0 Then If MsgBox("您确定吗", vbOKCancel) Then Unload Me Else Cancel = True End If End If End Sub 你可能不明白我的意思 我是希望直接关掉 不要有这个提示
king06 你创个a.exe Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) If UnloadMode = 0 Then If MsgBox("您确定吗", vbOKCancel) Then Unload Me Else Cancel = True End If End If End Sub就这点代码测试下就知道了
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As LongPrivate Const WM_CLOSE = &H10Private Sub cmdCloseApp_Click()
Dim CloseIt As Long
CloseIt = FindWindow(vbNullString, "ccc")
PostMessage CloseIt, WM_CLOSE, CLng(0), CLng(0)
End Sub
If UnloadMode = 0 Then
If MsgBox("您确定吗", vbOKCancel) Then
Unload Me
Else
Cancel = True
End If
End If
End Sub这样PostMessage 后出来的是对话框,我不希望他出现对话框,希望他直接关闭 有什么办法吗?
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Const WM_CLOSE = &H10Private Sub Command1_Click()
Dim lngTmp As Long
lngTmp = FindWindow(vbNullString, "P1")
Call SendMessage(lngTmp, WM_CLOSE, 0, 0)
End Sub
现在是可以关闭了 但是有另外一个问题
但是我在a.exe里有这样的代码 Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If UnloadMode = 0 Then
If MsgBox("您确定吗", vbOKCancel) Then
Unload Me
Else
Cancel = True
End If
End If
End Sub 这样PostMessage 后出来的是对话框,我不希望他出现对话框,希望他直接关闭 有什么办法吗?
其中pskill.exe是一个工具软件
If UnloadMode = 0 Then
If MsgBox("您确定吗", vbOKCancel) Then
Unload Me
Else
Cancel = True
End If
End If
End Sub
你可能不明白我的意思 我是希望直接关掉 不要有这个提示
If UnloadMode = 0 Then
If MsgBox("您确定吗", vbOKCancel) Then
Unload Me
Else
Cancel = True
End If
End If
End Sub就这点代码测试下就知道了