In that case you can use the SendMessage API and the WM_CLOSE Message to tell an Application to Close, eg.
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 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
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]




Reply With Quote