Link to home
Start Free TrialLog in
Avatar of 49407211
49407211

asked on

End Task or Application from VB

How i can end task o application from VB 5.0 ?
Avatar of stevesm
stevesm

There must be something more. What kind of task?

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

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)  
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.
Avatar of 49407211

ASKER

Don't work, application continue opened
ASKER CERTIFIED SOLUTION
Avatar of mrmick
mrmick

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial