Scribble’s View: Class CScribbleView

The job of the view in Scribble is to redraw the view as needed — for example, when the window is covered by another window and then uncovered, or as the user draws strokes with the mouse.

Suggested Reading

  • , Visual C++ Programmer’s Guide

Views in Scribble are objects of class CScribbleView, which is derived from class CView. CScribbleView knows how to access the document’s stroke list and can tell the strokes stored there to draw themselves in the view.

You can view a graphical representation of CScribbleView and its member functions in the ClassView pane of the Project Workspace window.

The following table describes the member functions of class CScribbleView that AppWizard created for you.

CScribbleView Member Functions

Member Description
CScribbleView, ~CScribbleView With nothing to initialize and no data to destroy, the view’s constructor and destructor are empty.
OnDraw OnDraw updates the view by redrawing its contents. (It’s used to draw both on the screen and on a printer.)
GetDocument Defined inline in file ScribbleView.h, GetDocument retrieves a type-safe pointer to the document attached to this view. The view uses the pointer to call document member functions, which it must do to access the data it displays.
AssertValid, Dump These diagnostic functions simply call the base-class functions they override.
OnPreparePrinting, OnBeginPrinting, OnEndPrinting These virtual functions override the versions in CView to specify the application’s printing behavior. See Lesson 9, Enhancing Printing, for more information about how Scribble prints.

You won’t need to alter any of the following AppWizard-created functions in this lesson: GetDocument, AssertValid, Dump, OnPreparePrinting, OnBeginPrinting, and OnEndPrinting.

Notice the inline definition of GetDocument in the above table. The debug version of this member function calls the IsKindOf member function defined in class CObject and uses the RUNTIME_CLASS macro to retrieve the run-time class name of the document.