Transferred from: http://blog.csdn.net/bboot/article/details/26884011
Had to turn, instantly clarified a lot of questions, dapper
1.CWinApp class
It contains and manages all the information for the application's documentation/Windows. It has a member variable Cdocmanager*m_pdocmanager, which is the manager of the Document/window; m_templatelist is a list in Cdocmanager, which holds pointers to all document templates when the user calls CWinApp :: AddDocTemplate (Pdoctemplate) after the pdoctemplate was deposited in the Cwinapp::m_pdocmanager::m_templatelist list.
The following two functions are lookup and traversal operations on M_templatelist:
Cwinapp::getfirstdoctemplateposition ()//Get the location of the position type for the first document template
Cwinapp::getnextdoctemplate (Position&pos)//Get the document template for POS location and pass the Positoon location of the next template to Pos;
2.CDocTempplate class
Commonly used its derived classes CSingleDocTemplate class and CMultiDocTemplate class
(1). CSingleDocTemplate Class (Inheritance and Cdoctempplate Class)
You can open only one document at a time and one view or more to open multiple types of documents (open one to close another document)
(2). CMultiDocTemplate Class (Inheritance and Cdoctempplate Class)
This is a very important class. Cmultidoctemplate::m_doclist holds a list of pointers to the document instances for all such documents. The following two functions are used to maintain cmultidoctemplate::m_doclist data
Cmultidoctemplate::adddocument (cdocument* pDoc);
Cmultidoctemplate::removedocument (cdocument* pDoc);
The following two functions are used to sample all document instances of the document type.
Cmultidoctemplate::getfirstdocposition () const;
Cmultidoctemplate::cdocument*getnextdoc (position&rpos) const;
3.CDocument class
CDocument Each document instance can have more than one view corresponding to it.
Cdocument::m_viewlist is used to save all view associated with this document instance
Cdocument::getdoctemplate can obtain an instance of the corresponding document template such as the CMultiDocTemplate type of document template;
4, CView class
For example, in the framework of multiple document views, each CMDIChildWnd has a view
Cview::getdocument can obtain CDocument related to this view
Cview::getparentframe () can obtain CMDIChildWnd;
The above analysis shows that Cwinapp,cmdichildwnd,cview,cdocument,cmultidoctemplate knows that one of the instances must know all the other instances, and CWinApp commands the global Any time a CWinApp instance is obtained, all document template document instances, views, frame windows can be enumerated. AfxGetApp () Gets the CWinApp instance pointer.