PDA

Click to See Complete Forum and Search --> : Closing a program...


jgomes
Nov 26th, 1999, 05:38 AM
How do I close a program thats running with VB? For example, if I had notepad open, how would I close it using an API?
thx...a lot

-Justin =]

Antonio Begue
Nov 26th, 1999, 06:16 AM
Option Explicit
Private Const WM_CLOSE = &H10

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
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Sub CloseMirc()
Dim hNotepad As Long
hNotepad = FindWindow("mIRC32", vbNullString)
Call SendMessage(hNotepad, WM_CLOSE, 0, ByVal 0&)
End Sub

Private Sub Command1_Click()
CloseMirc
End Sub


This example shous you how to close a running program like mirc
you need to know the real name of the program like in this case (mIRC32)