Analysis of the MFC Framework Program and the mfc framework
The program framework of MFC:
WinMain function: The program first reaches the global variable theApp, then the theAPP constructor, and finally the WinMain function.
Q: Why do I need to define a global object theAPP so that it can be executed before the WinMain function?
A: In win32 applications, the application instance is identified by the instance handle hInstance. For MFC programs, the application instance is uniquely identified by generating an application object, each MFC program has only one class derived from the application class CWinAPP, and has only one instantiated object from the derived class.
Implementation of the message ing mechanism of MFC: defines a static comparison table between messages and message functions in each class that can receive and process messages. In the message ing table, the message is paired with the corresponding message processing function pointer. The addresses of all messages that a class can process and their corresponding message processing functions are listed in the static table corresponding to this class. When a message needs to be processed, the program only needs to search for the static table of the message and check whether the table contains the message. This class can process the message, the corresponding message processing function can be easily found and called Based on the static table.
Differences between a modal dialog box and a non-modal dialog box:
The dialog box can be divided into two types based on the working method:
1. Modal Dialog Box: Before closing the modal dialog box, the program cannot perform other work (such as the general "Open File" dialog box)
Create Modal Dialog Box
CTestDlg dlg;
dlg.DoModal();
2,Non-Modal Dialog Box: after the non-modal dialog box is opened, the program can still perform other work (such as the "search and replace" dialog box)
CTestDlg * dlg = new CTestDlg; dlg->Create(IDD_TEST_DLG); dlg->ShowWindow(SW_SHOW);
Because the non-Modal Dialog Box object is built using the new operator, you must use the delete operator to delete the dialog box object after the dialog box is closed. After a window is deleted on the screen, the Framework calls CWnd: PostNcDestroy, which is a virtual function. The program can delete window objects in this function. The Code is as follows:
Void CModelessDialog: PostNcDestroy {delete this; // delete object CDialog: PosNcDestroy ();}
In this way, after the dialog box is deleted, the dialog box objects are automatically deleted. The owner does not need to explicitly call delete to delete the dialog box objects.