Basic Tasks for Adding Scrolling

The basic tasks for adding scrolling to your application are as follows:

  1. Define a size for your documents. This can be a constant, a member stored in each document object, or a value calculated at run time, for example.

  2. Derive your view class from CScrollView instead of CView.

    Note   In the AppWizard – Step 6 dialog box, you have the option of changing your base class. You could have, for example, chosen CScrollView instead of CView at that point, thereby eliminating some of the steps in this procedure.

  3. Pass the document’s size to the SetScrollSizes member function of CScrollView whenever the size may change.

  4. Convert between logical coordinates and device coordinates if passing points between graphic device interface (GDI) and non-GDI functions.

The framework’s responsibilities are as follows:

  • Handle all WM_HSCROLL and WM_VSCROLL messages, scroll the document in response, and move the scroll box accordingly.

    The positions of the scroll boxes reflect where the currently displayed portion of the document resides relative to the rest of the document:

    • If the user clicks a scroll arrow at either end of the scroll bar, the document scrolls one “line” (whose meaning depends on the document type).

    • If the user clicks either side of the scroll box, the document scrolls one page.

    • If the user drags the scroll box itself, the document scrolls accordingly.

  • Calculate a mapping between the lengths of the scroll bars and the height and width of the document, adjust this scaling factor when the window is resized or when the size of the document changes, and in turn remove or add scroll bars as needed.

The figure below shows Scribble with scroll bars added.

Scribble with Scrolling Support