Zooming In on a Selection: Step 6

In the MainWndProc function, add code to process WM_LBUTTONUP messages. This code defines the source and destination rectangles for painting, and forces a repaint. The code should appear as follows:

case WM_LBUTTONUP: 
EndGDIX = LOWORD(lParam); 
EndGDIY = HIWORD(lParam); 
/* Use the mouse position's percentage offsets in the image rectangle 
to determine the pixel offsets in the bitmap. 
Using percentages allows for the possibility that the image is zoomed. */ 
EndPixelX = MulDiv(BITMAPWIDTH(&LeadBitmap), EndGDIX - rLeadDest.left, DisplayWidth); 
EndPixelY = MulDiv(BITMAPHEIGHT(&LeadBitmap), EndGDIY - rLeadDest.top, DisplayHeight); 
/* Do nothing if no area is defined */ 
if ((EndPixelX == StartPixelX) || (EndPixelY == StartPixelY)) 
   return (0); 
/* Get the source rectangle coordinates for painting. 
Allow for different mouse drag directions */ 
if (StartGDIX < EndGDIX) 
{ 
   rLeadSource.left = StartPixelX; 
   rLeadSource.right = EndPixelX; 
} 
else 
{ 
   rLeadSource.left = EndPixelX; 
   rLeadSource.right = StartPixelX; 
} 
if (StartGDIY < EndGDIY) 
{ 
   rLeadSource.top = StartPixelY; 
   rLeadSource.bottom = EndPixelY; 
} 
else 
{ 
   rLeadSource.top = EndPixelY; 
   rLeadSource.bottom = StartPixelY; 
} 
/* Use this local function (described in Fitting an Image to a Window) to 
center the cropped display in the client area. */ 
CalcDisplay (rClientSize.right,   /* Width allowed */ 
rClientSize.bottom,  /* Height allowed */ 
rLeadSource.right - rLeadSource.left, /* Width factor, for aspect ratio */ 
rLeadSource.bottom - rLeadSource.top, /* Height factor, for aspect ratio */ 
&DisplayTop,         /* Resulting top value, for centering */                 
&DisplayLeft,        /* Resulting left value, for centering */                 
&DisplayWidth,       /* Resulting width value */ 
&DisplayHeight);     /* Resulting height value */ 
/* Set the destination rectangle for painting */ 
SetRect(&rLeadDest, DisplayLeft, DisplayTop, 
DisplayLeft + DisplayWidth, DisplayTop + DisplayHeight); 
/* If necessary, translate the source rectangle to the bitmap's view perspective */ 
if (LeadBitmap.ViewPerspective != TOP_LEFT) 
   L_RectToBitmap(&LeadBitmap, TOP_LEFT, &rLeadSource); 
/* Repaint the whole client area */ 
InvalidateRect(hWnd,NULL,TRUE); 
return (0); 

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

LEADTOOLS Raster Imaging C API Help