Preliminary framework of MFC

Source: Internet
Author: User

MFC ---- Microsoft basic class. Microsoft developed a series of Windows-based classes using C ++ according to market requirements. These classes are called by users in a similar way through APIS, shortening the development cycle.

Similar to a DOS program, each MFC-based user program has a winmain function, which is the entry of the application program. Other functions must be called in the function. However, this function is not visible in visual stdio, because Microsoft should encapsulate it and complete the framework construction and related code addition during the process of generating the framework program using the wizard. The winmain function is linked to the application during the link process.

Each MFC program has an app class, which uniquely identifies an application. A global theapp object is defined in the application. During program compilation, all global variables will be initialized first, so the constructor will be called, which is derived from its parent class cwinapp and further called its parent class constructor. The constructor calls the _ twinmain () function. This function is actually implemented through the afxwinmain function. afx represents the application framework function. The application framework is actually a framework model that assists in generating applications, this model organically integrates multiple classes. You can design your own applications based on the solution provided by the model. All functions starting with afx are global functions.

MFC Framework Window

1. design the registration window

MFC designed a series of default window classes, as long as you call and register these window classes. Registered by afxenddeferregisterclass.

2. Create a window

The Window Creation function is implemented by the createx function of the cwnd class. The declaration of this function is in the afxwin. h file, and the implementation code is in the wincore. cpp file.

3. The update window is displayed.

The initinstance function of the ctestapp class contains the following code:

M_pmainwnd-> showwindow (sw_show );

M_pmainwnd-> updatewindow ();

MFC program running process

1. Use the global application object theapp to start the application.

2. Call the constructor of the Global Object of the application to initialize the application.

3. Enter the winmain function.

4. Enter the message loop. When you receive the wm_quit message, exit the message loop and the application ends.

Basic Framework of the mfc sdi application

When App Wizard is used to generate an application framework, four basic application classes are generated: ctest1app (Application class), cmainframe (main framework window class), and ctest1doc (document class) and ctest1view (View class ).

The ctest1app class is used to manage the entire application, complete routine initialization of the application, centrally manage the messages received by the application, and allocate messages to other objects of the application, finally, the application is cleaned up.

The cmainframe class manages the main window of the program, including the title bar, status bar, tools, and maximization functions. You do not need to perform such operations because it inherits the Message Processing Features of windows.

The ctest1doc class reads and writes data and performs I/O operations. The document class encapsulates the data management function of the application.

Ctest1view is responsible for displaying the read data. This class interacts with the document class and is a subwindow of the Framework Window.

The interaction between a class and a class is transmitted through a Windows message and operated by calling the public data member of the class.

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.