The creation of MFC objects
The previous chapters introduce MFC's core concepts and ideas, that is, introduce MFC's encapsulation methods and features of Windows objects; Dynamic creation, serialization of MFC objects, and MFC message mapping mechanisms.
Now, examine MFC's application architecture, which is document-as the core programming model. To learn this chapter, you should clarify the following questions:
MFC relationships for many MFC objects: Application object, Document object, Border window object, Document Border Window object, object, document template object, and so on.
Creation and destruction of MFC objects: What objects Create or destroy what objects, when to create, and when to destroy?
What interfaces does MFC provide to support its programming mode?
The Relationship of MFC objects
Create a relationship
This discusses the creation relationships of applications, document templates, border Windows, visual, document, and so on. Figure 5-1 illustrates the order of creation, but table 5-1 shows more directly the relationship between creation and creation.
Table 5-1 MFC object Creation Relationship
Created by |
The object being created |
Application objects |
Document templates |
Document templates |
Document |
Document templates |
Border window |
Border window |
As |
Interactive relationships
The Application object has a list of document templates that holds one or more document template objects; The document template object has a list of open documents that holds one or more open document objects; The Document object has a view list that holds one or more objects that display the document's data ; There is also a pointer to the document template object that created the document; A pointer to its associated document is treated as a child window whose parent window is a border window (or a Document border window); A document border window has a pointer to its current active view; The document border window is a child of the border window.
Windows manages all windows that are already open and sends messages or events to the target window. Typically, a command message is sent to the main border window.
Figure 5-2 shows the above relationship in a very approximate way: