Step 2: Set a WinEvent Hook

[This is preliminary documentation and subject to change.]

After initializing the COM library, you must set a WinEvent hook by calling the SetWinEventHook function. The Babble application calls this function in its InitMSAA application-defined function. The following code illustrates how to call SetWinEventHook.

BOOL InitMSAA(void) {
  // Set up an event hook.
  hEventHook = SetWinEventHook(EVENT_MIN,         // We want all events
                               EVENT_MAX,
                               GetModuleHandle(NULL),// Use this module
                               WinEventProc,
                               0,        // All processes
                               0,        // All threads
                               WINEVENT_OUTOFCONTEXT);
    // Did we install correctly? 
    if (hEventHook)
        return(TRUE);

    // Did not install properly - fail
    return(FALSE);
}
 

Note InitMSAA specifies the EVENT_MIN and EVENT_MAX event constants. This causes Active Accessibility to notify the hook procedure for all possible events. Additionally, InitMSAA tests the returned hook identifier to determine if the hook was successfully installed. If the return value is non-NULL, then the call succeeded.

For more information, see WinEvents.