As we all know, the process of windows API programming and message processing is clearly visible. The general steps are as follows:
1) Declare the message window class
2) Registration window class
3) createwindows
4) Obtain and dispatch messages (windows procedure ).
However, the process for MFC is also a Windows program is not clear. The specific analysis is as follows:
There are two important classes in MFC: CWinApp and CFrameWnd. The existence of these two classes replaces the existence of WinMain and WinProc in a sense.
An Application Object (theApp) exists in any MFC program. Because it is a global Object, it is the entry point of a program,
After TheApp is constructed, the linker adds WinMain to the application and calls the AfxWinMain () function. (In CExampleApp theApp; In this step, as long as you press F11 to continue, it will go to crtexe. mainret = WinMain... in c ..., the F11 will go to appmodul. return AfxWinMain (hInstance, hPrevInstance, lpCmdLine, nCmdShow) in cpp)
Then, in AfxWinMain, AfxWinInit (), pApp-> InitApplication (), pApp-> InitInstance (), pApp-> Run (); AfxWinTerm (); complete the entire process of the program.
About InitInstance: first, it will create a new CFrameWnd member. Its constructor calls create (); create () calls createEx (), and createEx () calls PreCreateWindows ();
By default, MFC registers five types of Window Types (Wnd, controlbar, mdiframe, FrameOrView, and OleControl ).
Message process: it mainly calls AfxWndProc-> AfxCallWndProc-> Wnd. WindowProc ().
This is actually the real processing process of the program. First, determine whether the message is a WM_COMMAND message. If not, perform the processing according to the common method (query the message ing table and create the memory table by the macro ),
Is handled according to the routes specified by MFC. CWnd: OnCommand () calls on1_msg (). Here, MFC specifies the message route (view, document, framewnd, winapp ).