Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Chapter 5: The Document/View Architecture Visual C++ and MFC Fundamentals


5.1 Overview of the Document/View Architecture.......................................


5.1.1 Introduction...........................................................................................


The Document/View architecture is the foundation used to create applications based on
the Microsoft Foundation Classes library. It allows you to make distinct the different
parts that compose a computer program including what the user sees as part of your
application and the document a user would work on. This is done through a combination
of separate classes that work as an ensemble.

The parts that compose the Document/View architecture are a frame, one or more
documents, and the view. Put together, these entities make up a usable application.

5.1.2 The View...............................................................................................


A view is the platform the user is working on to do his or her job. For example, while
performing word processing, the user works on a series of words that compose the text. If
a user is performing calculations on a spreadsheet application, the interface the user is
viewing is made of small boxes called cells. Another user may be in front of a graphic
document while drawing lines and other geometric figures. The thing the user is starring
at and performing changes is called a view. The view also allows the user to print a
document.

To let the user do anything on an application, you must provide a view, which is an
object based on the CView class. You can either directly use one of the classes derived
from CView or you can derive your own custom class from CView or one of its child
classes.

5.1.3 The Document......................................................................................


A document is similar to a bucket. It can be used to hold or carry water and that water can
be retrieved when needed. For a computer application, a document holds the user's data.
For example, after working on a text processor, the user may want to save the file. Such
an action creates a document and this document must reside somewhere. In the same
way, to use an existing file, the user must locate it, open it, and make it available to the
application. These two jobs and many others are handled behind the scenes as a
document.

To create the document part of this architecture, you must derive an object from the
CDocument class.

5.1.4 The Frame.............................................................................................


As its name suggests, a frame is a combination of the building blocks, the structure (in
the English sense), and the borders of an item. A frame gives "physical" presence to a
window. A frame defines the location of an object with regards to the Windows desktop.
A frame provides borders to a window, borders that the user can grab to move, size, and
resize the object. The frame is also a type of desk that holds the tools needed on an
application.
Free download pdf