L_SetStatusCallBack

#include "l_bitmap.h"

L_VOID EXT_FUNCTION L_SetStatusCallBack(pfnCallback, pUserData)

STATUSCALLBACK pfnCallback;

/* pointer to your callback function */

L_VOID L_FAR * pUserData;

/* pointer to more parameters for the callback */

STATUSCALLBACK L_FAR * pfnOldCallback;

/* pointer to old callback function */

L_VOID L_FAR * L_FAR * ppOldUserData;

/* pointer to more parameters for the old callback */

Sets the new status callback function and gets the old status callback.

Parameter

Description

pfnCallback

Pointer to your callback function. The callback function must adhere to the function syntax specified in STATUSCALLBACK Function.

 

This callback function must return SUCCESS if the operation was successfully done, or any error if the function call was a failure. If the callback function returns a failure, the current function will terminate and return the same error that the callback returned.

pUserData

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 L_FAR *. 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.

pfnOldCallback

Pointer to a variable which will be updated with the old status callback function

ppOldUserData

Pointer to a variable which will be updated with the user data for the old status callback function

Returns

None.

Comments

The status callback is returned through a parameter. You used to have to call L_GetStatusCallBack to get the user data prior to calling L_SetStatusCallback. Now you can get the old callback and set the new callback in one function call.

You can use this function to specify a callback for any of the following functions:

L_AddBitmapNoise
L_AverageFilterBitmap

L_BinaryFilterBitmap

L_ChangeBitmapContrast

L_ChangeBitmapHue

L_ChangeBitmapIntensity

L_ChangeBitmapSaturation

L_ClearBitmap

L_ColorMergeBitmap

L_ColorSeparateBitmap

L_CombineBitmap

L_DeskewBitmap

L_DespeckleBitmap

L_EmbossBitmap

L_FillBitmap

L_FlipBitmap

L_GammaCorrectBitmap

L_GetBitmapHistogram

L_GrayScaleBitmap

L_HalfToneBitmap

L_HistoEqualizeBitmap

L_IntensityDetectBitmap

L_InvertBitmap

L_MedianFilterBitmap

L_MMConvertFromBitmapList(Video Module only)
L_MMSaveFile(Video Module only)
L_MosaicBitmap

L_PaintDCEffect

L_PosterizeBitmap

L_PrintBitmap

L_RemapBitmapIntensity

L_ResampleBitmap

L_ResizeBitmap

L_ReverseBitmap

L_RotateBitmap

L_RotateBitmapFine

L_SharpenBitmap

L_ShearBitmap

L_SizeBitmap

L_SpatialFilterBitmap

L_StretchBitmapIntensity

L_UnderlayBitmap

Both the old status callback function and the user data required for the old status callback function are updated in the pfnOldCallbaclk and ppOldUserData parameters, respectively.

1.

Call the L_SetStatusCallBack function, assigning its return value to a STATUSCALLBACK variable, and passing the pointer to your callback as the new value.

2.

Call the function that uses the callback (for example L_AverageFilterBitmap).

3.

Call the L_SetStatusCallBack function again, restoring the original value by passing the variable that you saved in Step 1.

Required DLLs and Libraries

LTKRN

For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application.

Platforms

Windows 95 / 98 / Me, Windows 2000 / XP, Windows CE.

See Also

Functions:

STATUSCALLBACK, L_GetStatusCallBack

Topics:

Using Callback Functions

Example

For complete sample code, refer to the CHILD.C module of the DEMO example.

/**************** Global declarations
***********************************************/
HINSTANCE hInst;          /* Current instance of the application, set by the
InitInstance function */
BITMAPHANDLE LeadBitmap;  /* Bitmap handle for the loaded image */
L_BOOL KillProgress;      /* Boolean flag to test for a user interrupt */
L_BOOL InterruptActive;   /* Boolean flag to enable use of an interrupt key
*/

/* Prototype for the STATUSCALLBACK function */
L_INT L_EXPORT EXT_CALLBACK StatusCallBack (L_INT nPercent, L_VOID L_FAR*
pUserData);

/* This function uses L_SetStatusCallBack to implement the STATUSCALLBACK
function when applying a median filter. */
void TestFunction(HWND hWnd)
{
   STATUSCALLBACK lpfnOldStatusCB;  /* Pointer to the previous
STATUSCALLBACK function */
   L_VOID L_FAR* pOldData; /* Pointer to the user data for the previous status callback function */
   /* Set the STATUSCALLBACK function, saving the pointer to the previous
one */
   L_SetStatusCallBack(StatusCallBack, NULL, &lpfnOldStatusCB, &pOldData );
   /* Initialize global variables for detecting a user interrupt */
   InterruptActive = TRUE;
   KillProgress = FALSE;
   /* Apply an intentionally slow median filter with a neighborhood of 7x7
pixels */
   L_MedianFilterBitmap(&LeadBitmap, 7 );
   /* Disable the user interrupt key */
   InterruptActive = FALSE;

   /* Restore the previous STATUSCALLBACK function */
   L_SetStatusCallBack (lpfnOldStatusCB, pOldData, NULL, NULL);
   /* Force a repaint */
   InvalidateRect(hWnd,NULL,FALSE);
   return;
}

/* This is the STATUSCALLBACK function, which stops the process
if the user has pressed the interrupt key. */
L_INT L_EXPORT EXT_CALLBACK StatusCallBack (L_INT nPercent, L_VOID L_FAR
*pUserData)
{
   HWND hWnd=NULL;
   L_TCHAR achMsg[80]; /* MessageBox string */
   MSG msg;

   hWnd = (HWND)pUserData;

   /* Let the application detect a WM_KEYDOWN event */
   while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
   {
      TranslateMessage (&msg);
      DispatchMessage (&msg);
   }

   /* Check the global variable and return an error if necessary */
   if (KillProgress)
   {
      wsprintf (achMsg, TEXT("Interrupted by the user with %d percent finished"),
nPercent);
      MessageBox (hWnd, achMsg, TEXT("Notice"), MB_OK);
      return (ERROR_USER_ABORT);
   }
   return SUCCESS;
}

/* This is the main window processing function, where the interrupt key is
detected */

L_INT32 EXT_FUNCTION MainWndProc (HWND hWnd, L_UINT Message, WPARAM wParam,

LPARAM lParam)

{

switch (Message)

{

case WM_KEYDOWN:

/* Use the Esc key as the user interrupt key */

if (((int) wParam == VK_ESCAPE) && (InterruptActive == TRUE))

KillProgress = TRUE;

 

/* Use the Insert key to run the test function */

if ((int) wParam == VK_INSERT)

TestFunction (hWnd);

}

return (0);

}