When a modal form is displayed, and the user switches to another app, the access window may become minimized. This is not possible manualy but done through some other apps code. By clicking on the access button on the toolbar, the app cannot be restored or maxmized except through taskmanager.
Set a windows hook into access to intercept any message that tells access to minimize when ever the modal window is displayed. Or try to capture the mouse click on the button in the toolbar after it hs been minimized to then send a message to access to to restore the window.
Below is the code that I have written to set the hook. This code works when the SetWindowsHook HookID value is set to WH_CBT. The callback function is called and every thing is fine. I can't use the CBT message as the window has already begun to minimize and I cant cancel the action. The problem occurs when I set the HookID to WH_GETMESSAGE. The call back is called the first time when a message is received, but then Access will crash.
Private Declare Function SetWindowsHookEx Lib "user32" _
Alias "SetWindowsHookExA" (ByVal idHook As Long, _
ByVal lpfn As Long, _
ByVal hmod As Long, _
ByVal dwThreadId As Long) As Long
Private Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Private Declare Function GetCurrentThreadId Lib "KERNEL32" () As Long
Private Declare Function GetModuleHandle Lib "KERNEL32" Alias _
"GetModuleHandleA" (ByVal lpModuleName As String) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal ncode As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WH_CALLWNDPROC = 4
Private Const WH_CALLWNDPROCRET = 12
Private Const WH_CBT = 5
Private Const WH_DEBUG = 9
Private Const WH_FOREGROUNDIDLE = 11
Private Const WH_GETMESSAGE = 3
Private Const WH_HARDWARE = 8
Private Const WH_JOURNALPLAYBACK = 1
Private Const WH_JOURNALRECORD = 0
Private Const WH_KEYBOARD = 2
Private Const WH_KEYBOARD_LL = 13
Private Const WH_MAX = 11
Private Const WH_MAXHOOK = WH_MAX
Private Const WH_MIN = (-1)
Private Const WH_MINHOOK = WH_MIN
Private Const WH_MOUSE = 7
Private Const WH_MOUSE_LL = 14
Private Const WH_MSGFILTER = (-1)
Private Const WH_SHELL = 10
Private Const WH_SYSMSGFILTER = 6
Dim hHook As Long
Dim lngThreadId As Long
Dim lngModHWnd As Long
Public Function SetHook() As Boolean
On Error GoTo Err_SetHook
If hHook = 0 Then
lngThreadId = GetCurrentThreadId
lngModHWnd = GetModuleHandle(vbNullString)
hHook = SetWindowsHookEx(WH_CBT, AddressOf HookCallback, lngModHWnd, lngThreadId)
If hHook <> 0 Then
SetHook = True
Debug.Print "Hook Set"
SetHook = False
Debug.Print "Hook NOT Set"
Public Function RemoveHook() As Boolean
On Error GoTo Err_RemoveHook
If hHook <> 0 Then
hHook = 0
RemoveHook = True
Debug.Print "Hook Removed"
Private Function HookCallback(ByVal Code As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Debug.Print "Code: " & Code & " cParam: " & wParam & " lParam: " & lParam
HookCallback = CallNextHookEx(hHook, Code, wParam, lParam)
Any ideas anyone?