Zooming In on a Selection

If you are using the high-level LBitmapWindow (or derived) class, zooming in on a selection is done automatically for you when you set the tool to TOOL_ZOOMRECT using LBitmapWindow::SetToolType. The class object will automatically handle the mouse events for you, and adjust the bitmap's display rectangles in order to zoom in on the user-defined rectangle.

If you are not using LBitmapWindow, this topic describes how to let the user select an area with a mouse and zoom in on the selected area. In this topic, you learn the following:

How to use the source rectangle with the LPaint::PaintDC function.

How to translate client area coordinates to bitmap coordinates, while accounting for differences in view perspective. For general information about view perspectives, refer to Accounting for View Perspective.

 

1.

Add this code to load an image and init the display rectangles.

2.

Add these global variables for tracking coordinates to your program.

3.

Add this code to process WM_LBUTTONDOWN messages. This code initializes coordinates for defining two rectangles. One rectangle is relative to the client area and is used with the GDI functions to outline the selection. The other rectangle is relative to the bitmap and is used to zoom in by defining the source rectangle for painting.

4.

Add this code to process WM_MOUSEMOVE messages. This code outlines the selection using GDI functions.

5.

Add this code to process WM_LBUTTONUP messages. This code defines the source and destination rectangles for painting, and forces a repaint (CalcDisplay is defined below).

6.

Add this code to process WM_RBUTTONDOWN messages. This code returns to the display of the full image when the user clicks the right mouse button.

7.

Add this code to process WM_PAINT messages. This code sets the bitmap rectangles and paints the image.