Library code snippets
Close Application by Caption
By Mike J, published on 07 Mar 2002
The code
Place the following code in a module
Option Explicit
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Const WM_CLOSE = &H10
'THIS WILL CLOSE AN APP BY CAPTION ONLY
Public Sub CloseProgram(ByVal Caption As String)
On Error GoTo EVT
Dim lngWin As Long
lngWin = FindWindow(vbNullString, Caption)
If lngWin = 0 Then Exit Sub
SendMessage lngWin, WM_CLOSE, 0&, 0&
Exit Sub
EVT:
Err.Clear
Resume Next
End Sub
call the code above by Call CloseProgram("My Applications Caption")
Please note that the code above will terminate without notcie if an error occures.
This is to make it as stealth as possible. Avoiding bugs and stuff.
If anyone has a good example on how to do this without knowing any part of the caption, basically doing it by closing a runing EXE file, I would very much appreciate an email about that.
Related articles
Related discussion
-
Problem with migration to C# (CoCreateInstanceEx)
by LRollison (1 replies)
-
VB6 Problem Creating Shortcuts
by rb1177 (0 replies)
-
how can i open a file
by kyawswarhtun (0 replies)
-
how to save any one form what i want?
by blackguy (5 replies)
-
Build an MP3 Player
by soybees (4 replies)
Related podcasts
-
Christian Beauclair
14 mai 2008 (�mission #0074) ::.Christian Beauclair: Stratégies de migration VB6 vers .NET Nous discutons avec Christian Beauclair des stratégies de migration VB6 vers .NET. Entre autres, nous discutons comment utiliser le "VB 6 Code Advisor" et le "Interop Forms Toolkit" pour ajouter la puiss...
This thread is for discussions of Close Application by Caption.