ycsim
Nov 5th, 1999, 09:19 AM
How do we close a program forcefully without going through then Unload Procedure???
------------------
YC Sim
Teenage Programmer
UIN 37903254
Aaron Young
Nov 5th, 1999, 09:37 AM
End
------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
adyoung@win.bright.net
ycsim
Nov 5th, 1999, 09:42 AM
I mean... an external program.
------------------
YC Sim
Teenage Programmer
UIN 37903254
Aaron Young
Nov 5th, 1999, 10:10 AM
In that case you can use the SendMessage API and the WM_CLOSE Message to tell an Application to Close, eg.
Private Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) 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
Private Const WM_CLOSE = &H10
Private Sub Command1_Click()
Dim tPoint As POINTAPI
Dim lHwnd As Long
Call GetCursorPos(tPoint)
lHwnd = WindowFromPoint(tPoint.x, tPoint.y)
Call SendMessage(lHwnd, WM_CLOSE, 0, 0)
End Sub
If that doesn't shut it down, you can use the TerminateProcess API, but be warned, this will Forcefully Shutdown whatever you pass it, no questions asked.
Private Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
Private Const PROCESS_ALL_ACCESS = &H1F0FFF
Private Sub Command1_Click()
Dim tPoint As POINTAPI
Dim lHwnd As Long
Dim lPID As Long
Dim lCode As Long
Call GetCursorPos(tPoint)
lHwnd = WindowFromPoint(tPoint.x, tPoint.y)
Call GetWindowThreadProcessId(lHwnd, lPID)
lPID = OpenProcess(PROCESS_ALL_ACCESS, 0&, lPID)
Call GetExitCodeProcess(lPID, lCode)
Call TerminateProcess(lPID, lCode)
End Sub
------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
adyoung@win.bright.net