Views

The document object defines, stores, and manages the application’s data. All user interaction with the document is managed through a view object attached to the document object. Scribble uses a view object to display a document on the screen or on a printer. This topic introduces the role of the view and Scribble’s view class and members.

Suggested Reading

When a new document is created in response to a New or Open command from the File menu, the framework also creates a document frame window and creates a view inside the frame window’s client area as a child window. The view displays the document’s data and responds to mouse actions, keystrokes, menu commands, and other actions as the user works on the document. It is your task to specify how the view draws your application-specific data and what it does in response to user actions.

The figure below illustrates the view’s role in relation to the document.

The View and the Document

In the framework, the document manages data, but the view displays it and acts as intermediary between the user and the document for all input, selection, and editing in the document. A given view is always associated with only one document. However, it is possible for a document to have multiple views associated with it. In MDI applications such as Scribble, for example, the Window menu contains commands to open a new view onto a document, and to arrange open documents. In Scribble, you’ll also add splitter window functionality, enabling the user to create a second view onto a document without opening a new window.

The following table shows your responsibilities and those of the framework in implementing a view on a document.

View Implementation Responsibilities

Your job The framework’s job
Derive a view class from class CView. For scrolling, use CScrollView instead. Other view classes are available as well. AppWizard provides a starter view class for you. Class CView and its derived classes provide view services.
Implement your view’s OnDraw member function. The framework calls OnDraw at the appropriate times, passing it a device-context object into which it can draw.
Map Windows messages and commands to member functions of your view. The framework calls your message-handler member functions in response to the corresponding Windows messages.