Data and View
In our previous examples of CArchive we have taken member variables of CStudent class and showed how to save and retrieve data to and from file stream. Again there was a diaglog example to exchange student data attributes between UI and these member variables. Here we have data and display UI part in one single dialog file. We write small applications and we often do data management and data display part in a single module. This is however is not a good design. We face design issues when we scale up our application and deals with multiple data modules. There is a design need to have different modules to manage data and display separately.
Document View Architecture
MFC Document View Architecture is a framework to manage user module data and view of the module separately. The design it follows is known as model-view architecture. Data part is managed by model and in MFC this is known as Document and display part is managed by view class.
Document is the class to manage data part of the objects. Application often derives a class from CDocument. This deals with saving and retrieving data fields to and from the file stream. MFC often uses CArchive and serialization process to do the same. Users however have other options like direct CFile calls to synch the data to file syatem or query SQL server to do the same. Document module also deals with the logic to maintain the data and also responsible for managing different attributes of the data.
View is the class module to display data of the document. A derived class of CView is often used for this purpose. This display part can be the display of the document in graphical form or with UI elements or in the form of printable view which contains formatted text.
FrameMFC framework uses a Frame window or class CFrame to display window in the screen and thus a CFrame class is always needed in any application which follows document view architecture.
Document View Block diagram
Document and View Advantages
This design may look complex for a small dialog based application. However this actually helps when dealing with a large application where there are multiple data objects and different view of the objects. This design decouples data from view.
Data managing part may go separate changes where display part can remain unchanged. Again there can be display part to change where data manage part can remain same. For both the cases this design fits well. There are possibilities that there is need to change the entire interface of document save retrieve part. Say we have migrated from CArchive data file to database thus the entire data logic part can be changed independently. Again view can also be changed independently. Say we migrated to HTML view from dialog view then also changes in view part can be independent. Doc view architecture can also fits well for the documents for multiple views like a document of student object can be viewed in dialog when taking inputs from user then same can be in graphical page view when we print of display for viewing.
About our authors: Team EQA
MFC hides WinMain in its framework and includes source file on WinMain(). This explains how framework calls global CWinApp::Initinstance() from entry WinMain.
This is constructed during global C++ objects are constructed and is already available when Windows calls the WinMain function, which is supplied by the ...
Define a custom Window class structure, Register the class name, CreateWindow, Show windows and write message get and dispatch loop statements. Define the Window CallBack procedure and write the handlers.
DispatchMessage() is a API which indirectly triggers the Window CallBack procedure. Message structure members from this function are passed to the CallBack procedure. CallBack procedure should implement event handlers depending on the need of the application.
LPARAM and WPARAM are the two parameters in Window CallBack procedure. They signifies parameters of various events. They are used in handing individual events.
We need to write WinMain and need to follow all these in a Win32 application. However we need not to write much if we are writing an application with MFC ...
Learn on Youtube