Condividi tramite


_ActivateHandler( ) API Library Routine

Adds a handler function to the end of the list of event handlers.

unsigned int _ActivateHandler(FPFI handler)
FPFI handler               /* Event handler to be added. */

Remarks

_ActivateHandler( ) returns an integer identifier for this handler. Use this identifier to remove the handler from the event processor list with _DeActivateHandler( ).

The handler is invoked with two parameters: the WHANDLE of the window to which the event belongs**,** and a FAR (32-bit) pointer to an event record. If your handler doesn't look for an event, or modifies an event for subsequent event handlers, it returns False (0) to indicate that the event must still be passed on to other handlers or to the Visual FoxPro interface routines. If the handler determines that the event doesn't need to be passed on, it returns True (an integer other than 0) to indicate that the event has been handled.

For more information on how to create an API library and integrate it with Visual FoxPro, see Accessing the Visual FoxPro API.

Example

The following example activates an event handler when the library is loaded. The event handler prints a message for every event and lets Visual FoxPro process the event as it does normally. The event handler is deactivated when the library is unloaded.

Visual FoxPro Code

SET LIBRARY TO ACTIHAND
WAIT WINDOW TO m.test TIMEOUT 5
SET LIBRARY TO

C Code

#include <pro_ext.h>

static int HandlerID;

//   This is the routine that is registered as an event handler.
FAR EventHandler(WHandle theWindow, EventRec FAR *ev)
{
   _PutStr("\nEventHandler() called.");
   return NO;   // event still needs to be handled by Visual FoxPro
}

FAR Activate()
{
   HandlerID = _ActivateHandler(EventHandler);
}

//   When the library is unloaded we must deactivate the event handler
//   in a CALLONUNLOAD function.
FAR DeActivate()
{
   _DeActivateHandler(HandlerID);
}

FoxInfo myFoxInfo[] = {
   {"ACTIVATE",  Activate,   CALLONLOAD, ""},
   {"DEACTIVATE", DeActivate, CALLONUNLOAD, ""}
};
FoxTable _FoxTable = {
   (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo
};

See Also

_DeActivateHandler( ) API Library Routine | _FindWindow( ) API Library Routine | _GlobalToLocal( ) API Library Routine | _MousePos( ) API Library Routine | Event Handlers | EventHandler( ) Function