For true graphic applications, it is necessary to zoom into the view to see details of the drawing. Using CScrollView to minimize programming effort, one way to do this is to set the scroll size bigger according to the zoom factor. As an example, if you have an A4 document size (210mm x 296mm), you can tell CSrollView that your document size is 420mm x 592mm so you have a zoom of 2. To do this, simply call SetScrollSizes(MM_LOMETRIC, CSize(4200, 5920)). When doing this, we have a problem. The maximal size of CScrollView is 32768 x 32768. In other words, the zoom is limited to 32768/2960=11.07.
Using CScrollView to scroll, the client size moves only into CScrollView size. Reaching the sides of CScrollView size, the CScrollSize moves into CBigScrollView size. The only problem doing this it that the scroll bars doesn't reflect the CBigScrollView size but the CScrollSize instead. This is acceptable else it is necessary to rewrite entirely CScrollView. Zoom is limited to 2,147,483,648/2960=725.50.
CBigScrollView has the same properties than CScrollView. You can set the mapping mode like CScrollView. CBigScrollView doesn't use float type but only long type. No float arithmetic is made.
A problem using GDI functions is that clipping is doing only in valid range. When you draw a line into virtual range, you are responsible to clip the line into valid range like client rectangle or CScrollView size. This sample implements a line-clipping algorithm.
A problem zooming into the view is that the user expects that the center of the client size remains the same. To do this, it is necessary to save the center of the client size before zooming and restore it after this. This is true also when resizing the window.
This sample implements Zoom In, Zoom Out, Zoom Default, Zoom with rectangle and hand move functions. In Hand mode, when pressing the left mouse button, you can move the view. In the other mode selected with the toolbar or the right button, you can select a zooming rectangle.
This sample is compiled with Visual C++ 5.0.
Download demo project - 39424 KB
Download source & demo - 78400 KB
Date Posted: February 7, 1999