MFC C++

Lesson 2 : The Document/View Architecture

This MFC video tutorial briefly covers the Document/View architecture. Microsoft created this as a simple way to make GUI applications in Windows without having to learn a great deal about the Windows API. The Doc/View framework handles many of the basic things needed in any application, such as printing and saving/loading files, automatically. This is especially true if you use the AppWizard in Visual Studio to create an MFC project.

The architecture's main elements are the Document and the View classes. The Document class can be thought of as a generic container for any kind of data that an application uses, such as baseball scores, images, files names, text documents, etc. This class derives from CDocument. Its main purpose is to load the data when requested, to keep the data updated when a user changes it, and to save out the data to disk, database, or any other source.

The View class functions to show the user the data of the application in a formatted or stylized way:







This class derives from CView, and it is used to present the data to the user, take input in the form of mouse and keyboard events from the user, alert the document of the changes to the data that the user has requested, and update itself when the data changes.

There are two main ways to think of an MFC application: either as an SDI or an MDI program. SDI, or Single Document Interface, has only one Document and usually only one View (though it is possible through Splitter windows to use multiple Views).



MDI, or Multiple Document Interface, can support both multiple Documents and Views. An MDI application looks like multiple windows that can be minimized, maximized, or closed independently inside the main application window.







Currently, MDI is not utilized as much as the SDI architecture, but is still available in MFC if you wish to use it.

 

© 2007–2024 XoaX.net LLC. All rights reserved.