MFC Review (1)

Source: Internet
Author: User

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 ).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.