J
JF
Greetings,
I'm trying to add a Windows hook to capture the event when Access is
activated
(maximized, or switched to) from another application. I attempted some code
but I have a couple issues. I've implemented
the code below (omitting the API declarations for brevity) and it doesn't
quite work as expected. I set the hook in my app's startup form "load"
event (which happens to be a logon form). After the user logs in, the main
screen is loaded. However, the main screen doesn't get painted until I
switch to another application and then back to my app. At this point, the
activate message gets sent to my hook as expected, however, it happens about
six times. Then, the main screen won't process any events - I can't click
buttons, or other controls. Additionally, I can't even minimize, or even
close the whole app. If I switch to another app, and back to my app, the
activate goes off again but I still can't do anything. After doing this
several times, my whole system slows down with 100% utilization - mostly
being used by Access. Any ideas what I'm doing wrong?
<BEGIN CODE>
Private Type CWPRETSTRUCT
lResult As Long
lParam As Long
wParam As Long
Message As Long
hWnd As Long
End Type
Public Const WH_CALLWNDPROCRET = 12
Public Const WM_ACTIVATEAPP = &H1C
Public Const HC_ACTION = 0
Global g_hHook As Long
Public Function HookWindowProcRet(ByVal nCode As Long, ByVal wParam As Long,
_
ByVal lParam As Long) As Long
Dim oCWP As CWPRETSTRUCT
If nCode >= HC_ACTION Then
CopyMemory oCWP, ByVal lParam, Len(oCWP)
If oCWP.Message = WM_ACTIVATEAPP Then
If oCWP.wParam Then
MsgBox "App activated"
End If
HookWindowProcRet = 1
Exit Function
End If
End If
HookWindowProcRet = CallNextHookEx(hHook, nCode, wParam, lParam)
End Function
'The following code is located in the start up form's load event:
Dim hThreadID As Long
hThreadID = GetCurrentThreadId()
g_hHook = SetWindowsHookEx(WH_CALLWNDPROCRET, AddressOf
HookWindowProcRet, 0&, hThreadID)
<END CODE>
I'm trying to add a Windows hook to capture the event when Access is
activated
(maximized, or switched to) from another application. I attempted some code
but I have a couple issues. I've implemented
the code below (omitting the API declarations for brevity) and it doesn't
quite work as expected. I set the hook in my app's startup form "load"
event (which happens to be a logon form). After the user logs in, the main
screen is loaded. However, the main screen doesn't get painted until I
switch to another application and then back to my app. At this point, the
activate message gets sent to my hook as expected, however, it happens about
six times. Then, the main screen won't process any events - I can't click
buttons, or other controls. Additionally, I can't even minimize, or even
close the whole app. If I switch to another app, and back to my app, the
activate goes off again but I still can't do anything. After doing this
several times, my whole system slows down with 100% utilization - mostly
being used by Access. Any ideas what I'm doing wrong?
<BEGIN CODE>
Private Type CWPRETSTRUCT
lResult As Long
lParam As Long
wParam As Long
Message As Long
hWnd As Long
End Type
Public Const WH_CALLWNDPROCRET = 12
Public Const WM_ACTIVATEAPP = &H1C
Public Const HC_ACTION = 0
Global g_hHook As Long
Public Function HookWindowProcRet(ByVal nCode As Long, ByVal wParam As Long,
_
ByVal lParam As Long) As Long
Dim oCWP As CWPRETSTRUCT
If nCode >= HC_ACTION Then
CopyMemory oCWP, ByVal lParam, Len(oCWP)
If oCWP.Message = WM_ACTIVATEAPP Then
If oCWP.wParam Then
MsgBox "App activated"
End If
HookWindowProcRet = 1
Exit Function
End If
End If
HookWindowProcRet = CallNextHookEx(hHook, nCode, wParam, lParam)
End Function
'The following code is located in the start up form's load event:
Dim hThreadID As Long
hThreadID = GetCurrentThreadId()
g_hHook = SetWindowsHookEx(WH_CALLWNDPROCRET, AddressOf
HookWindowProcRet, 0&, hThreadID)
<END CODE>