table of Contents
Create a new project
Open visual studio, I used 2017 here, the creation of other versions is similar
The MFC board is installed by default here, and an MFC application named "test" is
created. To create a dialog-based MFC program, except for the "Dialog-based" in the second window, the rest of the defaults can go to
this dialog-based application. The MFC program of the box is created
The relationship between the object classes in the program
After the program is created, what we really need to care about is actually two files. The others are components provided by vs, namely, test.cpp and testDlg.cpp
. The specific functions of each file are explained in detail in the ReadMe.txt file.
As the main file of the program, test.cpp is the program source file.
testDlg.cpp is a window file, that is, a visualized window file.
The mfc program requires at least one application class (CtestApp) and one window frame class (CtestDlg), and the two classes together constitute the simplest MFC program
Program execution flow
Open an MFC project, the program execution process is as follows:
1.CtestApp theApp
That is, the global variable definition before the main function
2. Call the constructor
3. Enter Winmain function
This function is automatically provided after the project is created. It is not in the created project file, but hidden in the vs installation directory. I referenced a blog to find it, but I couldn't find it. A reference blog will be attached at the end.
4. Initialization
Will run the InitInstance() function in test.cpp
It also includes window class registration, window generation, display and update, and message loop
. The functions of the window are completed by the CtestDlg class, including the operations of the remaining controls and windows in the main window.
At this point, after the program has finished running, the following effects will appear
to sum up
A and complete MFC program, including at least an application class and a window frame class. Don't go into the use of similar controls in the details, the specific implementation of the function, it is still very simple to want to go up, but the specific implementation code in MFC is very unfamiliar, and even looks very complicated.
And the MFC program project is created. I don’t want the windows API program to see the execution process of the program from the beginning to the end. MFC encapsulates a lot of APIs, maybe the amount of code is reduced, but it also brings a lot of learning to beginners such as me. trouble.
I have referred to many blogs and wrote very detailed, limited to my own knowledge, but I still look at it in the cloud. I hope that the follow-up study can have a deeper understanding.