49407211
asked on
End Task or Application from VB
How i can end task o application from VB 5.0 ?
Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) _
As Long
Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Long) _
As Long
Dim lpClassName As String
Dim lpCaption As String
Dim Handle As Long
Const NILL = 0&
Const WM_SYSCOMMAND = &H112
Const SC_CLOSE = &HF060&
lpClassName = "Class name of the program to be terminated"
lpCaption = "The caption of the program to be terminated" .
Handle =FindWindow(lpClassName$, lpCaption$)
Handle = SendMessage(Handle, WM_SYSCOMMAND, SC_CLOSE, NILL)
(ByVal lpClassName As String, _
ByVal lpWindowName As String) _
As Long
Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Long) _
As Long
Dim lpClassName As String
Dim lpCaption As String
Dim Handle As Long
Const NILL = 0&
Const WM_SYSCOMMAND = &H112
Const SC_CLOSE = &HF060&
lpClassName = "Class name of the program to be terminated"
lpCaption = "The caption of the program to be terminated" .
Handle =FindWindow(lpClassName$, lpCaption$)
Handle = SendMessage(Handle, WM_SYSCOMMAND, SC_CLOSE, NILL)
sorry,
one error
Const SC_CLOSE=&HF060 and not with the & at the end.
Also for the class name of the application , you can use vbnullstring.
one error
Const SC_CLOSE=&HF060 and not with the & at the end.
Also for the class name of the application , you can use vbnullstring.
ASKER
Don't work, application continue opened
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Put a command button on your main form with the following code.
Call your command button cmdClose as in this example.
Private Sub cmdClose_Click()
Unload Me 'unload the form
End 'ends the applications
End Sub