Products | Support | Send comments on this topic. | Email a link to this topic. | Back to Getting Started | Help Version 18.0.11.1
LEADTOOLS Raster Imaging C DLL Help

Zooming In on a Selection: Step 6

Show in webframe

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);

Products | Support | Contact Us | Copyright Notices
© 2006-2014 All Rights Reserved. LEAD Technologies, Inc.