1. Overview
Document/view is an MFC-based framework integrated in Viaual C + +. Implementation of the operation of the data display.
Consists of three main parts:
CFrameWnd (frame window): The so-called frame window refers to the main window of the entire application including menus, toolbars, status bars, and window client areas, equivalent to the main window mentioned in the simple application framework.
CDocument (document): Data as a data member of a document class, centrally managed by the document class, and the document class is directly associated with the disk for data storage and reading.
CView (view): Derived from the CWnd Class for managing window client areas in a document/view structure. Designed to render and edit the application's data, there is an important function in the view Class OnDraw (), which is used for application data display and is generally overridden in derived classes. The OnDraw () function will centrally manage the display of all your data.
Related classes in the 2.document/view structure
In general, the application of a Document/view structure consists of the following 5 classes: Cwinapp,cframewnd,cdocument,cview,cdoctemplate
2.1 CWinApp
The CWinApp object represents the program ontology. Encapsulates operations that have fairly fixed behavior in MFC, such as the initialization Order of MFC programs:
- CMyWinApp Theapp; -----> This is the global variable in the program, it is unique, before the WinMain () function is constructed, some member variables in CWinApp are configured and the initial value because of the birth of Theapp this global variable;
- Theapp configuration, Afxwinamain () debut, first call the global function AfxGetApp () function, get pointer to Theapp;
- AfxWinInit (... Implementation
- Papp->initapplication (), the function is generally not overridden, so the call is Cwinapp::initapplication (), the function is to initialize the Cdocmanager class. The Cdomanager class maintains a linked list of CDocTemplate pointers, CDocTemplate objects created in InitInstance and added to the list "
- Papp->initinstance (), each subclass overrides InitInstance () because there is no definition in the base class. Where you start creating the frame window (p=new cmyframewnd ();p->showwindow ()//Display window; P->updatewindow ()//Send a WM_PAINT here? Don't know what to do for the moment.
- Papp->run (), "Fountainhead of the program", enters the message loop. The subclass does not rewrite Run (), so the call (and in turn) is CWinApp::Run () >cwinthread::run () >cwinthread::P umpmessage () >::translatemessage () and::D ispatchmessage () message processing
To create a new program to inherit CWinApp directly, the production line has been assembled.
2.2 CFrameWnd
A frame window is the main window of the entire application that includes menus, toolbars, status bars, and window client areas, which is equivalent to the main window mentioned in the simple application framework. In the MFC program, generally do not need to operate the CFrameWnd class frequently, to view the customer area and a number of operational menus, etc.;
2.3 CDocument
Centralized management of data. Data is used as its member data, can interact with disk, write data to disk or read from disk (rely on serialize () function to complete data Access Task)
A. Maintain a pointer to a document template that can be used to set the caption, notify the document template when the document is deleted, etc.
B. Maintaining a pointer to an open view list for view and document communication
2.4 CView
Presentation and editing of data in document. Use the OnDraw () function to present the data, but the application's data is stored in the document class, and the view class returns a pointer to the document class through the function GetDocument (), which gives access to the public data members in the document class.
2.5 CDocTemplate
The role of document template classes (CDocTemplate) is to centrally manage cframewnd,cdocument and CView, and treat them as a whole. It also loads the menus and resources such as shortcut keys for using an ID with the menu resource;
It is generally derived from a class: CMultiDocTemplate and CSingleDocTemplate,
3 Some important functions
Title Error: Functions and Functions in the CView class *
========================================
Pictures stolen from http://blog.sina.com.cn/s/blog_62ce00c90100ld9h.html
========================================
MFC Document/view 2