Third, MFC program structure analysis
The framework of the SDK and the MFC application is listed in the previous respectively, and the correspondence between them is slightly. But for the MFC program, if you want to really understand its framework, it is not enough.
The first is to see what major files in the MFC application generated by the application wizard, which are included and related classes and the relationship between them.
In the SDI application above, the wizard generates four main classes, which are derived classes of the MFC class, which are included in the corresponding header files and implementation files.
1, frame window and its related files
The frame window class corresponds to the main window of the application. After this, you can build a sense of sensibility to this class, and his definition is in the headfront mainfrm.h, and the implementation is in the mainfrm.cpp file. All functions with the frame window are defined and implemented here.
2, document class and related documents
The document class has no intuitive correspondence in the application, however, what we should know is that one feature of the MFC framework is the document / view structure. Here you can understand, for example, we have opened a file in Word. In fact, this file is a document, and we see this file a view, so the document provides the application's support, But what we really see is displayed by a view. The definition of document classes is in "Hello WorldDoc.h", and his implementation is in the "Hello WorldDoc.cpp" file.
3, view class and its related documents
The view class is used to display the contents of the document object. We see the interface in the Word program is a view. We want to modify the object that the picture first operate is a view, so the view class is as indicated by his name. That way, it provides things from the perspective of the user. The definition of the view class is in "Hello WorldView.h", the implementation is in the file "Hello WorldView.h".
4, application classes and their related documents
The initialization of the MFC application, start operation, and end are completed by the application object. The corresponding document is "Hello World.cpp" and "Hello World.h".
After roughly understanding the role of the application object, you can now look at the relationship between them (as shown in the following figure).
Application object
Document template object
Frame window object
View object
Document object
From the above figure, it can be generally seen between the relationship between the MFC application object. The application initiates an application object, then creates a document template object (managed by cdocmanager) in InitInstance, so that the application can manage documents, view, and frame windows by establishing a template object.
Because just beginner VC programming, the above is just a summary of what I have just learned, I really want to clearly understand the MFC program framework, I don't know what year, maybe I can't do clearly. ! (Full text)