Scrolling and Scaling Views
The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.
The latest version of this topic can be found at Scrolling and Scaling Views.
MFC supports views that scroll and views that are automatically scaled to the size of the frame window that displays them. Class CScrollView
supports both kinds of views.
For more information about scrolling and scaling, see class CScrollView in the MFC Reference. For a scrolling example, see the Scribble sample.
What do you want to know more about
Scrolling a view
Scaling a view
Scrolling a View
Frequently the size of a document is greater than the size its view can display. This may occur because the document's data increases or the user shrinks the window that frames the view. In such cases, the view must support scrolling.
Any view can handle scroll-bar messages in its OnHScroll
and OnVScroll
member functions. You can either implement scroll-bar message handling in these functions, doing all the work yourself, or you can use the CScrollView
class to handle scrolling for you.
CScrollView
does the following:
Manages window and viewport sizes and mapping modes
Scrolls automatically in response to scroll-bar messages
You can specify how much to scroll for a "page" (when the user clicks in a scroll-bar shaft) and a "line" (when the user clicks in a scroll arrow). Plan these values to suit the nature of your view. For example, you might want to scroll in 1-pixel increments for a graphics view but in increments based on the line height in text documents.
Scaling a View
When you want the view to automatically fit the size of its frame window, you can use CScrollView
for scaling instead of scrolling. The logical view is stretched or shrunk to fit the window's client area exactly. A scaled view has no scroll bars.