Document-View Architecture in MFC |
||||||||||||||||||||||||
| PGUI: Document-View Architecture in MFC | ||||||||||||||||||||||||
| Contents: |
The document-view application architecture in MFC includes
The application pumps event messages to the frame window and to the view object. The view object (and the frame window) processes messages and calls the document interface to change the document. The document object send notification of the changes to the view objects.
The document object and the view objects are connected with a document template. The applications CSingleDocTemplate* pDocTemplate; pDocTemplate = new CSingleDocTemplate( IDR_MAINFRAME, RUNTIME_CLASS(CDiagramDoc), RUNTIME_CLASS(CMainFrame), RUNTIME_CLASS(CDiagramView)); AddDocTemplate(pDocTemplate);
The document is connected to the file type with the document template string included in the application resources (with the id "Diagram\n\nDiagram\nDiagram Files (*.dgr)\n.dgr\n Diagram.Document\nDiagram Document" The frame window routes user commands to the different parts of the application. Example programThe example program has been created with the help of the MFC AppWizard. The whole initial creation process is described in a separate page.
The complete example is available in the Diagram Example -page. DocumentIn the example: Node.h, Node.cpp DiagramDoc.h, and DiagramDoc.cpp
The document object holds the document data. In the example program the documents data is represented with two helper classes
The document class inherits CDocument base class. The example program uses CArray template class to store the nodes and the connectors. CArray<Node*, Node*> m_nodes; CArray<Connector*, Connector*> m_connectors;
The most important member functions (operations) of
The most important overridable members functions are
ViewIn the example: DiagramView.h and DiagramView.cpp. The view class includes the functionality of both view and controller of MVC. It processes user input and also presents the document to the user. The view class inherits the CView base class. It is the simplest view class in MFC.
The view gets a reference to the document with a wizard-generated member function CDiagramDoc* CDiagramView::GetDocument()
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDiagramDoc)));
return (CDiagramDoc*)m_pDocument;
}
The most important overridable member functions of
|
See also: |
||||||||||||||||||||||
| Jarkko Leponiemi, Tuesday, 04-Nov-2003 07:32:14 EET | ||||||||||||||||||||||||