Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

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


class, you cannot directly use it in your application. You have two main alternatives. You
can derive your own class based on CView (the CView class itself is based on CWnd) or
you can use one of the many view classes that the MFC provides. The classes that are
readily available to you are:

Class Description
CEditView Used for a basic text editing application

CRichEditView Allows creating rich documents that perform text and paragraph
formatting
CScrollView Provides the ability to scroll a view horizontally and vertically
CListView Provides a view that can display a list of items
CTreeView Allows displaying a list of items arranged as a tree

CFormView Used to create a view that resembles a dialog box but provides the
document/view features

CDaoRecordView Provides a view that resembles a dialog box but used for database
controls

CCtrlView

Provides parental guidance to the CEditView, CListView,
CTreeView, and CRichEditView

As we move on, we will study these classes as needed.

Once you have a frame, a document, and a view, you can create an application, which, as
we have learned so far, is done by deriving a class from CWinApp and overriding the
InitInstance() method. In the InitInstance() implementation, you must let the compiler
know how a document is created in your application. To do this, you must provide a
sample document, called a template, that defines the parts that constitute a document for
your particular type of application. This is done using a pointer variable declared from
CDocTemplate or one of its derived classes.

5.2 The Single Document Interface (SDI)......................................................


5.2.1 Overview...............................................................................................


The expression Single Document Interface or SDI refers to a document that can present
only one view to the user. This means that the application cannot display more than one
document at a time. If the user wants to view another type of document of the current
application, he or she must another instance of the application. Notepad and WordPad are
examples of SDI applications:
Free download pdf