0% found this document useful (0 votes)
53 views

Experiment No. 2: Aim: - Get Familiar With Essential Classes in A Typical (Document-View Architecture) VC++

The document describes the document-view architecture used in MFC applications. It explains that there are typically four main classes: the document class, which manages application data; the view class, which handles user interaction and displaying data; the frame class, which contains UI elements; and the application class, which starts the program. The document-view architecture provides a flexible framework that divides responsibilities between these classes. It allows applications to be extended easily by changing individual classes without affecting the others.

Uploaded by

ankitsaahil
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views

Experiment No. 2: Aim: - Get Familiar With Essential Classes in A Typical (Document-View Architecture) VC++

The document describes the document-view architecture used in MFC applications. It explains that there are typically four main classes: the document class, which manages application data; the view class, which handles user interaction and displaying data; the frame class, which contains UI elements; and the application class, which starts the program. The document-view architecture provides a flexible framework that divides responsibilities between these classes. It allows applications to be extended easily by changing individual classes without affecting the others.

Uploaded by

ankitsaahil
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Experiment No.

2
Aim: - Get familiar with essential classes in a typical (Document- view architecture)VC++
Program and their relationship with each other.
Parts of Application
The application source code generated for you by AppWizard actually consists of 4 major
classes. All these classes can be seen by expanding the class listing in the Class View tab.
For each of these classes corresponding header file (.h) and an implementation file (.cpp) is
generated.
The MainFrame Window Class
This class is named CMainFrame and is derived from the MFC class CFrameWnd. This
class manages the main window of the application that contains the window frame, Menu
bar, Toolbar, Status bar, System menu and Minimise, Maximise and Close boxes and also
contains the view window of the application.
The Application Class
This class named C ProjectNameApp is derived from the MFC class CWinApp. It manages
the application as a whole by managing the tasks, like initialising the application instance,
managing the message loop and performing final cleanup of the program.
The Document Class
This class named C ProjectNameDoc is derived from the MFC class CDocument. It is
responsible for storing the program data as a single string and reading and writing this
data to disk files.
The View Class
The class named C projectNameView is derived from CView class from the MFC classes.It
manages the view window, which is used to display program data on the screen and also
used in processing the input from the user.
MFC and AppWizard use the Document/View architecture to organize programs written for
Windows. Document/View separates the program into four main classes:

A document class derived from CDocument


A view class derived from CView
A frame class derived from CFrameWnd
An application class derived from CWinApp

Each of these classes has a specific role to play in an MFC Document/View application.
The document class is responsible for the program's data. The view class handles
interaction between the document and the user. The frame class contains the view and other
user interface elements, such as the menu and toolbars. The application class is responsible
for actually starting the program and handling some general-purpose interaction with
Windows. Figure shows the four main parts of a Document/View

The Document/View architecture.


Although the name "Document/View" might seem to limit you to only word-processing
applications, the architecture can be used in a wide variety of program types. There is no
limitation as to the data managed by CDocument; it can be a word processing file, a
spreadsheet, or a server at the other end of a network connection providing information to
your program. Likewise, there are many types of views. A view can be a simple window, as
used in the simple SDI applications presented so far, or it can be derived from CFormView,
with all the capabilities of a dialog box.
SDI and MDI Applications
There are two basic types of Document/View programs:
SDI, or Single Document Interface
MDI, or Multiple Document Interface
An SDI program supports a single type of document and almost always supports only a
single view. Only one document can be open at a time. An SDI application focuses on a
particular task and usually is fairly straightforward.
Several different types of documents can be used in an MDI program, with each document
having one or more views. Several documents can be open at a time, and the open
document often uses a customized toolbar and menus that fit the needs of that particular
document.
Why Use Document/View?
The first reason to use Document/View is that it provides a large amount of application
code for free. You should always try to write as little new source code as possible, and
that means using MFC classes and letting AppWizard and ClassWizard do a lot of the
work for you. A large amount of the code that is written for you in the form of MFC
classes and AppWizard code uses the Document/View architecture.
The Document/View architecture defines several main categories for classes used in a
Windows program. Document/View provides a flexible framework that you can use to

create almost any type of Windows program. One of the big advantages of the
Document/View architecture is that it divides the work in a Windows program into welldefined categories. Most classes fall into one of the four main class categories:
Controls and other user-interface elements related to a specific view
Data and data-handling classes, which belong to a document
Work that involves handling the toolbar, status bar, and menus, usually belonging to the
frame class
Interaction between the application and Windows occurring in the class derived from
CWinApp
Dividing work done by your program helps you manage the design of your program more
effectively. Extending programs that use the Document/View architecture is fairly simple
because the four main Document/View classes communicate with each other through
well-defined interfaces. For example, to change an SDI program to an MDI program, you
must write little new code. Changing the user interface for a Document/View program
impacts only the view class or classes; no changes are needed for the document, frame, or
application classes.

DOCUMENTS
Documents are the basic elements that are created and manipulated by the application.
Windows provides a graphic interface that gives a user a natural way to use the
application. To implement this interface, the developer has to provide ways to see and
interact with the information that the application creates and uses.
A document is simply a place to collect common data elements that form the processing
unit for the application.
Documents and the Application Relationship
The application class uses documents as a way to organize and present information to the
user. Each application derived from the MFC defines at least one type of document that is a
part of the application. The type of document and the number of documents that the
application uses are defined in the code of the application class.
As we have already discussed, MFC supports two types of applications MDI and SDI.
MDI - In applications that support Multiple Document Interface, a number of text files can
be opened for editing at once; each in a different window. Each of the open files has a
corresponding document. Also, in MDI, the same document can have multiple views,
where a window is split. Each pane of the window can show a different portion of the data
whereas this data is coming from a common source, the document.
SDI - In applications with Single Document Interface only one document is open at a
time. A SDI application does not have a Window menu and the File menu does not have a
Close option because only one document can be open at a time, opening a document
automatically closes the current document. These are two common characteristics of a SDI
application.
Why Documents
The fundamental responsibility of the document is to store all the elements that constitute an

application unit. An application may support more than one type of data like numbers, text,
drawings etc.
The document also controls all the views associated with it. As the user opens and
manipulates windows on the screen, views are created and the document is associated
with each view. The document is responsible for controlling and updating the elements
within a given view.
The view may either request the document to draw its components or directly request the
components to draw themselves. It must provide a device context where the drawing occurs.
All elements of a drawing must be able to display themselves correctly upon request.
VIEWS
The view is the users window to the document. The user interacts with a document using
the view. Each active document will have one or more active views available on the display.
Generally, each view is displayed in a single window.
Gaining Access to Document Data from the View
The view accesses its documents data either with the GetDocument() function, which returns
a pointer to the document or by making the view class a C++ friend of the document class.
The view then uses its access to the data to obtain the data when it is ready to draw or
otherwise manipulate it.For example, from the views OnDraw() member function, the
view usesGetDocument()to obtain a document pointer. Then it uses that pointer to access
a CString data memberin the document. The view passes the string to the TextOut()
function.

You might also like