Windows hook code for capturing Access activation

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>
 
D

david epsom dot com dot au

Your code show that you don't pass the wm_AppActivate
message on to the next hook procedure. Is this
deliberate?

(david)
 
J

JF

Yes, from what I read when I researched this code, if nCode is >= HC_ACTION
you don't have to call the CallNextHookEx function. In fact, I took a lot
of the code from a sample hook procedure.
 
J

JF

Thanks Stephen, I looked all over for my original post (via Outlook Express)
but couldn't find it which is why I posted the duplicate. I was able to
locate your response on Google Groups and will follow your advice.

JF
 

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