close another application

S

Sam

for closing another application i use the following code
it's work's ok but i have a little problem:
if the appliction changed the user get's a popup
asking for saveing yes or no
how can i force it to close with or without saveing?

thanks a head
sam

Private Const WM_CLOSE = &H10
Private Const INFINITE = &HFFFFFFFF

Private Declare Function apiPostMessage _
Lib "user32" Alias "PostMessageA" _
(ByVal hWnd As Long, _
ByVal wMsg As Long, _
ByVal wparam As Long, _
lparam As Any) _
As Long

Private Declare Function apiFindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) _
As Long

Private Declare Function apiWaitForSingleObject _
Lib "kernel32" Alias "WaitForSingleObject" _
(ByVal hHandle As Long, _
ByVal dwMilliseconds As Long) _
As Long

Private Declare Function apiIsWindow _
Lib "user32" Alias "IsWindow" _
(ByVal hWnd As Long) _
As Long

Private Declare Function apiGetWindowThreadProcessId _
Lib "user32" Alias "GetWindowThreadProcessId" _
(ByVal hWnd As Long, _
lpdwProcessID As Long) _
As Long

Function fCloseApp(lpClassName As String) As Boolean

Dim lngRet As Long, hWnd As Long, pID As Long

hWnd = apiFindWindow(lpClassName, vbNullString)
If (hWnd) Then
lngRet = apiPostMessage(hWnd, WM_CLOSE, 0, ByVal 0&)
Call apiGetWindowThreadProcessId(hWnd, pID)
Call apiWaitForSingleObject(pID, INFINITE)
fCloseApp = (apiIsWindow(hWnd) = 0)
End If
End Function

Public Function CloseAppl()
fCloseApp (fEnumWindows)
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top