Detecting and Closing an Activex Application from MS Access
I have created an ActiveX EXE that pops up a form which maintains a status...I can sucessfully invoke the application, as well as manipulate the data in the ActiveX application from MS Access. What I would like to be able to do is detect whether or not the ActiveX application is running, and if it is, send a command from MS Access to the ActiveX application to close down.
How I would do it is search for the window using FindWindowEx. If the window is found I would close it using SendMessage.
hWndApp = FindWindow("ThunderForm", <title>")
if (hwndapp <> 0) then
SendMessage (hwndApp, WM_CLOSE, 0, byval 0)
--
Public Const WM_CLOSE = &H10
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
0
dhouleAuthor Commented:
That worked great, thanks. How would I go about controlling MINIMIZE and RESTORE? The same way? &H?
hWndApp = FindWindow("ThunderForm", <title>")
if (hwndapp <> 0) then
SendMessage (hwndApp, WM_CLOSE, 0, byval 0)
--
Public Const WM_CLOSE = &H10
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long