Visual C + + MFC Concise Tutorial (2)

Source: Internet
Author: User
Tags exception handling new features advantage

Part Two: A simple MFC program

In this session, we will look at the MFC application mentioned in the previous section to understand its structure and conceptual framework. We'll introduce MFC first, and then we'll explain how to build an application with MFC.

Introduction to MFC

MFC is a large, expanded C + + class hierarchy that makes it easier to develop Windows applications. MFC is compatible throughout the Windows family, which means that MFC used for either windows3.x, Windows95, or Windows NT is compatible. Whenever a new version of Windows appears, MFC is also modified to allow the old compilers and code to work in the new system. MFC also extends back, adding new features and becoming easier to build applications.

In contrast to the traditional use of C for direct access to the Windows API, the advantage of using MFC and C + + is that MFC already contains and compresses all the standard "boilerplate" code that is required for all Windows programs written in C. Therefore, the program written in MFC is much smaller than the program written in C language. In addition, MFC writes the performance of the program is also no loss. If necessary, you can also call the standard C function directly, because MFC does not modify or hide the basic structure of Windows programs.

The biggest advantage of using MFC is that it does all the hardest things for you. MFC contains thousands of lines of correct, optimized, and powerful Windows code. Many of the member functions you call have done the work that you might find difficult to accomplish yourself. From this point on, MFC has greatly accelerated your program development speed.

MFC is very large. For example, version 4.0 contains about 200 different classes. Fortunately, you don't need to use all the functions in a typical program. In fact, you may only need to use the different classes in the 10 MFC to create a very beautiful program. The hierarchy can be divided into classes of several different types:

Application Framework

Drawing objects drawn by drawing

File Services

Exception handling

Structure-List, Array, and Map

Internet Services

OLE 2

Database

General class

In this tutorial, we'll focus on visual objects. The following list shows some of the classes:

CObject
CCmdTarget
CWinThread
CWinApp
CWnd
CFrameWnd
CDialog
CView
CStatic
CButton
CListBox
CComboBox
CEdit
CscrollBar

In the list above, there are a few points to note. First, most of the classes in MFC are inherited from the base class CObject. This class contains data members and member functions that are common to most MFC classes. Second, the simplicity of the list. The CWinApp class is used when you build an application and is used only once in any program. The CWnd class brings together all the common features, dialog boxes, and controls in Windows. The CFrameWnd class is inherited from the CWnd and implements the standard framework application. CDialog can handle both modeless and schema-type dialog boxes separately. CView is used to allow users to access documents through a window. Finally, Windows supports six types of controls: Static text boxes, editable text boxes, buttons, scroll bars, list boxes, and combo boxes (an extended list box). Once you understand this, you will have a better understanding of MFC. Other classes in MFC implement other features, such as memory management, document control, and so on.

In order to build an MFC application, you have to use these classes directly, and you usually need to inherit new classes from these classes. In the inherited class, you can create a new member function that works better for your own needs. You have seen this inheritance process in the simple example in the first lecture, which is described in detail below. Chelloapp and Chellowindow are inherited from an existing MFC 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.