|
APIs: Fermer une autre application |
Author(s) Dev Ashish |
|
(Q) Comment terminer une autre application, depuis Access?
(A) Pour terminer une autre application, il nous faut son nom
de classe Windows. Si vous ne le possédez pas, voir l'article "Find
ClassName of a Running App". Il s'agit alors de fournir ce nom à la
fonction fCloseApp.
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
Function fCloseApp(lpClassName As String) As Boolean
Dim lngRet As Long, lnghWnd As Long, lngX As Long
lnghWnd = apiFindWindow(lpClassName, vbNullString)
If lnghWnd <> 0 Then
lngRet = apiPostMessage(lnghWnd, WM_CLOSE, vbNull, vbNull)
lngX = apiWaitForSingleObject(lnghWnd, INFINITE)
fCloseApp = Not (apiIsWindow(lnghWnd) = 0)
End If
End Function
|