|
-
Nov 5th, 1999, 10:19 AM
#1
Thread Starter
Lively Member
How do we close a program forcefully without going through then Unload Procedure???
------------------
YC Sim
Teenage Programmer
UIN 37903254
-
Nov 5th, 1999, 10:37 AM
#2
End
------------------
Aaron Young
Analyst Programmer
[email protected]
[email protected]
-
Nov 5th, 1999, 10:42 AM
#3
Thread Starter
Lively Member
I mean... an external program.
------------------
YC Sim
Teenage Programmer
UIN 37903254
-
Nov 5th, 1999, 11:10 AM
#4
In that case you can use the SendMessage API and the WM_CLOSE Message to tell an Application to Close, eg.
Code:
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.
Code:
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
[email protected]
[email protected]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|