SHARE
Facebook X Pinterest WhatsApp

Breaking the CScrollView 32768 size limitation with CBigScrollView

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), […]

Written By
thumbnail
CodeGuru Staff
CodeGuru Staff
Feb 14, 1999
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

Recommended for you...

How To Make Windows 11 Faster
Enrique Stone
Nov 30, 2022
Working with the Windows Registry in C#
Joydip Kanjilal
Jun 17, 2022
Using Multiple Programming Languages to Create an ASP.NET Website
Tariq Siddiqui
Jun 11, 2022
Finding a Microsoft Office version with .NET
Hannes DuPreez
May 20, 2022
CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2025 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.