Breaking the CScrollView 32768 size limitation with CBigScrollView

CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.

For true graphic applications, it is necessary to zoom into the view to see details of the drawing.
Using CScrollView to minimize programming effort, the only 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.

bigscroll1.gif

Extending the scroll size capability.

To surpass the limitation of CScrollView, it is possible to calculate a new CBigScrollView size that
surpass the limitation of 32768 and calculate the origin of the CScrollView inside this new virtual size.

bigscroll2.gif

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.

Using CBigScrollView to Zoom into the view.

This sample use CBigScrollView to implement a CAppScrollView view with Zoom capabilities. MM_LOMETRIC is used
as mapping mode but you can use any valid mapping mode.

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.

Changing document size with Printer setup.

For true graphic applications, it is necessary to set the document size according to the printer paper size.
This sample reflects exactly the paper size. If you change the orientation or the paper size, a message is send
to the document to update views.

Download demo application (without source)- 15 KB

Download demo project – 75 KB

Date Last Updated: February 14, 1999

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read