Sets a new vector event callback.
#include "ltvkrn.h"
L_LVKRN_API L_INT L_VecSetEventCallback(pVector, pProc, pUserData, pOldProc, pOldUserData)
Pointer to a vector handle.
Your callback function that supplies the information that LEADTOOLS needs when handling events. The callback function must adhere to the syntax specified in VECTOREVENTPROC.
Void pointer that you can use to pass one or more additional parameters that the callback function needs.
To use this feature, assign a value to a variable or create a structure that contains as many fields as you need. Then, in this parameter, pass the address of the variable or structure, casting it to L_VOID *. The callback function, which receives the address in its own pUserData parameter, can cast it to a pointer of the appropriate data type to access your variable or structure.
If the additional parameters are not needed, you can pass NULL in this parameter.
Pointer to a pointer to a VECTOREVENTPROC that will be updated with the old callback function.
Pointer to the additional data used by the old callback function.
Value | Meaning |
---|---|
SUCCESS | The function was successful. |
< 1 | An error occurred. Refer to Return Codes. |
For information about the types of events the vector handle can generate, refer to the VECTOREVENT structure.
This example will disable L_VecSetRotation.
#define VECTOR_ERROR_USERNOROTATION -20000
typedef struct tagDATA
{
pVECTOREVENTPROC pOldProc;
L_VOID* pOldUserData;
}
DATA, *LPDATA;
L_INT EXT_CALLBACK VectorEventProc(pVECTORHANDLE pVector,
L_UINT uLevel,
pVECTOREVENT pEvent,
L_VOID* pUserData)
{
L_INT nRet;
LPDATA pData;
pData = (LPDATA) pUserData;
if (pData->pOldUserData != NULL)
{
/* call the old event handler */
nRet = pData->pOldProc( pVector, uLevel, pEvent, pData->pOldUserData );
if( nRet != SUCCESS )
return nRet;
}
/* disable rotation */
if( uLevel == 0 && /* top level event */
pEvent->uType == VECTOR_EVENT_ROTATION && /* from a L_VecSelectObject call */
pEvent->Status == VECTOR_EVENT_STATUS_BEFORE ) /* before any action is taken */
return VECTOR_ERROR_USERNOROTATION;
return SUCCESS;
}
L_LTVKRNTEX_API L_INT VecSetEventCallbackExample(pVECTORHANDLE pVector)
{
LPDATA pData;
/* set a new vector event callback */
pData = (LPDATA) GlobalAllocPtr( GHND, sizeof( LPDATA ) );
pData->pOldProc = NULL;
pData->pOldUserData = NULL;
return L_VecSetEventCallback( pVector, VectorEventProc, pData, &pData->pOldProc, &pData->pOldUserData );
}
L_VOID TestFunction( pVECTORHANDLE pVector )
{
L_INT nRet;
VECTORPOINT Point;
/* try to call L_VecSetRotation */
Point.x = 10.0;
Point.y = 20.0;
Point.z = 30.0;
nRet = L_VecSetRotation( pVector, &Point, NULL, NULL, 0L );
/* nRet should be VECTOR_ERROR_USERNOROTATION, the value returned from VectorEventProc */
}