Document and View Architecture:
1. Concept
of document and view architecture:
The document and view architecture consists of three parts.
The view, one or more document and frames.
i.
View:
The base class for view is CView. The view is platform on
which the user can view the stored data and he can edit that data.
ii.
Document:
The base class document is CDocument. The document is like a
buffer which simply stores all the user data or the file is saved on disk. This
saved file is called document.
iii.
Frame:
The base class for frame is CFrameWnd. This frame is physical
representation of windows. The frame provides the border to the window.
2. Menu:
Menu bar is an important element of any GUI. It is basically
a collection of various menu items. These items can be arranged on the pop-up
menu. User can select any item by clicking the top level items first then by
selecting the desired menu option. In Microsoft VC++ there is a menu resource
using which the menu can be created.
Ex:
Steps for creating Menu:
i.
Create new project using MFC
AppWizard
ii.
Goto Resource view
iii.
Goto Menu option in the list
iv.
Now default Menu will be shown in
main window. We can add new item by clicking on last blank box icon
3. Keyboard
Accelerators:
We have to make use of keyboard while using shortcut key.
Sometime one character is underlined; it indicates that press that character
along with the special key and that particular menu item will be selected. Such
underlined characters are hotkeys.
Some application designer may use of keyboard accelerator.
Keyboard accelerators are similar to the hot key for example in Microsoft word,
the short key F7 is used for spell check-up.
Steps for creating Menu:
i.
Create new project using MFC
AppWizard
ii.
Goto Resource view
iii.
Goto Accelerator option in the list
iv.
Now a list of all already
constructed accelerators will be shown in main window. We can add new accelerator
by right clicking on any already defined accelerator and selecting New
Accelerator option.
4. Tool
Bar:
A tool bar consists of horizontal arrangement of graphical
button, the graphical image for buttons are stored in a single bitmap that is
attached to single resource file. When a button is clicked, it sends a command
message.
Ex:
Steps for creating toolbar:
i.
Create new project using MFC
AppWizard
ii.
Goto Resource view
iii.
Goto Toolbar option in the list
iv.
Now a Toolbar will be shown in main
window. We can add new item by clicking on last blank box icon
Tool tips & prompt
string:
We can set the prompt string
by writing some string in the prompt window of particular menu item properties.
The prompt string can be displayed in the status bar window.
If we want to get tool tips
displayed on each button on the toolbar then that tool tip can be set by adding
the tip’s text to the end of menu prompt, preceded by a new line character (\n).
5. Status
Bar:
The status bar is another child window which is present at
the bottom of the main window. This window neither accepts input nor generates
any command, but used to display the help information.
The status bar is made up of two types of panes –
I.
Message line panes:
On the message line pane the help information can be
displayed.
II.
Indicator panes:
The indicator panes show current status of key, such as caps
lock, num lock, scroll lock is indicated.
In the mainFRM.CPP file the framework for status bar can be
defined as follows:
Static UINT indicators[]={ ID_Seprator, ID_INDICATOR_CAPS,
ID_INDICATOR_NUM, ID_INDICATOR_SCRL}
Class Wizard for status message –
6. Reusable
frame window Base class:
Any mainframe of window is derived from the class CframeWnd.
The reusable frame is kind of window frame that is derived from CframeWnd
Class.
But it remember following characteristics of the frame window
–
a. Window
size
b. Window
position
c. Window
status (Minimized| Maximized)
d. Toolbar
& Status bar getting enable &
disable
7. Separating
document from its view:
In the document view architecture the document object hold
data and the view object display the data of the user and allow him to edit
that data. In SDI application there are two Base classes CDocument & CView.
I.
CView::GetDocument():
Every view object is associated with only one document.
The GetDocument() function allow moving the control from view
to document. Sometimes on running the application, user enter the data in the
edit box that means the data is updated in view mode and this data must be
updated by the document object as well.
II.
CDocument::OnNewDocument();
The document framework first construct the document object
& when user click new menu item from the file then the OnNewDocument()
function is called. We can set some initial data for viewing on this new
document function.
III.
CDocument::UpdateAllView():
The UpdateAllView() function must be called when the data in
the document gets change and document must inform it to one or more view
associated with it.
IV.
CView::OnInitialUpdate():
When an application gets standard or when user click the new
from file menu or when user clicks on the open from the file menu, the CView
function is called at that time OnInitialUpdate () is called.
V.
CView::OnUpdate():
The
base class CView calls the OnInitialUpdate() function which in turn , calls
OnUpdate() function. The purpose of this function is to update all the view if
any change occur in the document data.