L_SetMagGlassOwnerDrawCallback

Summary

Sets a callback function, which lets the user provide custom magnifying glass rendering.

Syntax

#include "l_bitmap.h"

L_LTDIS_API L_INT L_SetMagGlassOwnerDrawCallback (hWnd, pfnCallback, pUserData)

Parameters

L_HWND hWnd

Handle of the window to which the magnifying glass is attached.

MAGGLASSOWNERDRAWCALLBACK pfnCallback

Callback function which be called every time the Magnifying Glass needs to be repainted.

The callback function must adhere to the function prototype described in MAGGLASSOWNERDRAWCALLBACK function.

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

Returns

Value Meaning
SUCCESS The function was successful.
< 1 An error occurred. Refer to Return Codes.

Comments

If a user-defined callback function is set by calling L_SetMagGlassOwnerDrawCallback, then after L_StartMagGlass is called and the Magnifying Glass paints itself to the DC, but before the Magnifying Glass is displayed on the screen, the user can change what is in the DC, through the user-defined callback function. This allows the user to provide custom rendering of the Magnifying Glass. For example, this feature lets you render magnified annotations, which may be overlaid on the currently displayed image, or just simply override what is currently in the Magnifying Glass display area.

Required DLLs and Libraries

Platforms

Win32, x64.

See Also

Functions

Structures

Topics

Example

NOTE, this is NOT a complete example!
This is an excerpt from the ANNOTATION Demo program.
For the complete code, refer to ANNOTATE.C.

typedef struct _MAGCHILDDATA 
{ 
   int            cxClient;      /* width of client area */ 
   int            cyClient;      /* height of client area */ 
   int            nHScrollPos;   /* x scroll position */ 
   int            nVScrollPos;   /* y scroll position */ 
   int            nHScrollMax;   /* maximum x scroll position */ 
   int            nVScrollMax;   /* maximum y scroll position */ 
   int            nHScrollStep;  /* x scroll step value */ 
   int            nVScrollStep;  /* y scroll step value */ 
   BOOL           bThumbTrack; 
   BOOL           fFitImage; 
   int            nZoom; 
   RECT           rcView; 
   RECT           rcClient; 
   RECT           rcWindow; 
   BITMAPHANDLE   Bitmap; 
   HPALETTE       hPalette; 
   HANNOBJECT     hContainer; 
   HANNOBJECT     hAutomation; 
   BOOL           fInScroll; 
   BOOL           fShowLock; 
   HANNOBJECT     hRect; 
   HANNOBJECT     hEllipse; 
   BOOL           fCapture; 
   BOOL           fLeftButtonDown; 
   POINT          pt0; 
   BOOL           bMagGlass; 
   L_INT          nMagWidth; 
   L_INT          nMagHeight; 
   L_INT          nMagZoom; 
   L_BOOL         bDoubleBuffer; 
   L_HANDLE       hDoubleBuffer; 
} MAGCHILDDATA, FAR* LPMAGCHILDDATA; 
 
L_INT EXT_CALLBACK MagGlassOwnerDrawCallback(L_HWND hWnd, 
   HDC hMemDC, 
   L_INT32 nXPos, 
   L_INT32 nYPos, 
   LPRECT pMagGlass, 
   L_VOID * pUserData) 
{ 
   UNREFERENCED_PARAMETER(hWnd); 
   LPMAGCHILDDATA pData = (LPMAGCHILDDATA)pUserData; 
   L_DOUBLE OffsetXOld = 0, OffsetYOld = 0; 
   L_DOUBLE OffsetX = 0, OffsetY = 0; 
   L_DOUBLE ScalarXOld = 0, ScalarYOld = 0; 
   L_DOUBLE ScalarX = 0, ScalarY = 0; 
   L_DOUBLE MagCenterX = 0, MagCenterY = 0; 
   L_DOUBLE BitmapX = 0, BitmapY = 0; 
   L_DOUBLE MagDestX = 0, MagDestY = 0; 
   RECT rc; 
 
   L_AnnPushFixedState(pData->hContainer, ANNFLAG_RECURSE | ANNFLAG_NOINVALIDATE); 
 
   L_AnnGetOffsetX(pData->hContainer, &OffsetXOld); 
   L_AnnGetOffsetY(pData->hContainer, &OffsetYOld); 
   L_AnnGetScalarX(pData->hContainer, &ScalarXOld); 
   L_AnnGetScalarY(pData->hContainer, &ScalarYOld); 
 
   MagCenterX = nXPos; 
   MagCenterY = nYPos; 
 
   BitmapX = (L_DOUBLE)(MagCenterX - pData->rcView.left) / ((L_DOUBLE)(pData->rcView.right - pData->rcView.left) / (L_DOUBLE)BITMAPWIDTH(&pData->Bitmap)); 
   BitmapY = (L_DOUBLE)(MagCenterY - pData->rcView.top) / ((L_DOUBLE)(pData->rcView.bottom - pData->rcView.top) / (L_DOUBLE)BITMAPHEIGHT(&pData->Bitmap)); 
 
   MagDestX = BitmapX * ((L_DOUBLE)(pData->rcView.right - pData->rcView.left) / (L_DOUBLE)BITMAPWIDTH(&pData->Bitmap)) * ((L_DOUBLE)pData->nMagZoom / 100.0f); 
   MagDestY = BitmapY * ((L_DOUBLE)(pData->rcView.bottom - pData->rcView.top) / (L_DOUBLE)BITMAPHEIGHT(&pData->Bitmap)) * ((L_DOUBLE)pData->nMagZoom / 100.0f); 
 
   OffsetX = ((L_DOUBLE)(pMagGlass->right - pMagGlass->left) / 2.0f) - MagDestX; 
   OffsetY = ((L_DOUBLE)(pMagGlass->bottom - pMagGlass->top) / 2.0f) - MagDestY; 
 
   ScalarX = (L_DOUBLE)(pData->rcView.right - pData->rcView.left) / (L_DOUBLE)BITMAPWIDTH(&pData->Bitmap) * ((L_DOUBLE)pData->nMagZoom / 100.0f); 
   ScalarY = (L_DOUBLE)(pData->rcView.bottom - pData->rcView.top) / (L_DOUBLE)BITMAPHEIGHT(&pData->Bitmap) * ((L_DOUBLE)pData->nMagZoom / 100.0f); 
 
   L_AnnSetOffsetX(pData->hContainer, OffsetX, ANNFLAG_NOINVALIDATE); 
   L_AnnSetOffsetY(pData->hContainer, OffsetY, ANNFLAG_NOINVALIDATE); 
   L_AnnSetScalarX(pData->hContainer, ScalarX, ANNFLAG_NOINVALIDATE); 
   L_AnnSetScalarY(pData->hContainer, ScalarY, ANNFLAG_NOINVALIDATE); 
 
   SetRect(&rc, 0, 0, pData->nMagWidth, pData->nMagHeight); 
   L_AnnDraw(hMemDC, &rc, pData->hContainer); 
 
   L_AnnSetOffsetX(pData->hContainer, OffsetXOld, ANNFLAG_NOINVALIDATE); 
   L_AnnSetOffsetY(pData->hContainer, OffsetYOld, ANNFLAG_NOINVALIDATE); 
   L_AnnSetScalarX(pData->hContainer, ScalarXOld, ANNFLAG_NOINVALIDATE); 
   L_AnnSetScalarY(pData->hContainer, ScalarYOld, ANNFLAG_NOINVALIDATE); 
 
   L_AnnPopFixedState(pData->hContainer, ANNFLAG_RECURSE | ANNFLAG_NOINVALIDATE); 
 
   return SUCCESS; 
} 
 
L_INT SetMagGlassOwnerDrawCallbackExample(L_HWND hwnd, LPMAGCHILDDATA pData) 
{ 
   L_INT nRet; 
   MAGGLASSOPTIONS Options; 
 
   nRet = L_AnnSetActiveState(pData->hAutomation, ANNACTIVE_DISABLED); 
   if (nRet != SUCCESS) 
      return nRet; 
 
   pData->nMagWidth = 200; 
   pData->nMagHeight = 200; 
   pData->nMagZoom = 200; 
 
   memset(&Options, 0, sizeof(MAGGLASSOPTIONS)); 
   Options.uStructSize = sizeof(MAGGLASSOPTIONS); 
   Options.nWidth = pData->nMagWidth; 
   Options.nHeight = pData->nMagHeight; 
   Options.nZoom = pData->nMagZoom; 
   Options.clrPen = RGB(0, 0, 0); 
   Options.hMagCursor = NULL; 
   Options.clrBack = RGB(128, 128, 128); 
   Options.bEllipse = FALSE; 
   Options.nBorderSize = 1; 
   Options.b3D = FALSE; 
   Options.uPaintFlags = 0; 
   Options.pMask = NULL; 
   Options.uMaskCount = 0; 
   Options.uMagGlassFlags = CROSSHAIR_FINE; 
   Options.nCrosshair = 1; 
   Options.bIgnoreRgn = TRUE; 
   Options.bCenter = TRUE; 
 
   nRet = L_StartMagGlass(hwnd, &pData->Bitmap, &pData->rcView, &Options, NULL, pData); 
   if (nRet != SUCCESS) 
      return nRet; 
 
   nRet = L_SetMagGlassOwnerDrawCallback(hwnd, MagGlassOwnerDrawCallback, pData); 
   if (nRet != SUCCESS) 
      return nRet; 
 
   pData->bMagGlass = TRUE; 
   return SUCCESS; 
} 

Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Raster Imaging C API Help
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.