First knowledge of MFC----MFC introduction, first knowledge of mfc ---- mfc

Source: Internet
Author: User

First knowledge of MFC----MFC introduction, first knowledge of mfc ---- mfc

I. Concepts and functions of MFC

1. What is MFC?

Full name: Microsoft Foundation Class Library (Microsoft Basic Class Library)

1-MFC is a library (static MFC Library and dynamic MFC Library) from the hard disk format)

2-MFC is a program framework in principle

2. Why is MFC used?

Framework-based programming improves work efficiency, reduces development cycles, and reduces development costs.

Ii. Several important header files

Afx. h -- contains the declaration of most classes in MFC

Afxwin. h -- contains afx. h and windows. h

Afxext. h -- provides support for extended classes, such as the toolbar, status bar...

Appendix: functions starting with Afx... can be identified as a global function in the MFC library;

Functions starting with:... can be identified as Win32 API functions;

Iii. Classification of MFC applications

1. Use the MFC library to create your own console Program

Compared with the Win32 console program:

A Global Object CWinApp theApp is added

The entry function is different from the previous entry function.

2. Use the MFC library to create your own static library program

3. Use the MFC library to create your own dynamic library program

1 -- use the MFC library to create its own rule dynamic library (static/dynamic MFC Library)

2 -- use the MFC library to create your own extended dynamic library

Difference: the rule repository can be called by all programs, and the extension library can only be called by programs supporting MFC.

4. Use the MFC library to create your own window Program

1 -- Single-document view framework

CFrameWnd-framework window class, which encapsulates the operations on the Framework Window

CWinApp-application class, which encapsulates operations on program processes

CDocument-document class, which encapsulates Data Operations (extraction, conversion, storage ...)

CView-View window class, which encapsulates operations on view Windows (drawing)

2 -- Multi-document view Framework Program

CMDIChildWnd-Sub-framework window class, which encapsulates operations on the sub-Framework Window

CMDIFrameWnd-main framework window class, which encapsulates operations on the main framework window

CWinApp-application class, which encapsulates operations on program processes

CDocument-document class, which encapsulates Data Operations (extraction, conversion, storage ...)

CView-View window class, which encapsulates operations on view Windows (drawing)

3 -- Dialog Box framework

CWinApp-application class, which encapsulates operations on program processes

CDialog-dialog box window class, which encapsulates operations on the dialog box window

Iv. Overview of classes in the MFC Library

1. The most basic class of most classes in the CObject-MFC Library

Encapsulate the most basic mechanisms in the MFC Library:

Runtime class information mechanism, dynamic creation mechanism, serialization Mechanism

2. The most basic class of the cve-target-message ing mechanism

3. CWinThread/CWinApp-application class, responsible for managing program processes

4. CDocument and its subclass-document class, responsible for data management

5. Exceptions-exception class, which encapsulates the handling of various Exceptions in MFC

6. CFile and its subclass-file operation class encapsulate operations on various files

7. The most basic class of the CWnd-window class encapsulates the most basic operations on the window.

8. Frame Windows-framework window class, which encapsulates operations on various framework Windows

9. The Dialog Boxes-Dialog box window class encapsulates operations on various Dialog box windows.

10. Views-View window class, which encapsulates operations on various view Windows

11. The Controls-control window class encapsulates operations on various control windows.

12. CDC and its Child classes-encapsulate various drawing devices and drawing functions

13. CGdiObject and its subclass-encapsulate operations on various drawing objects

14. CArrary/CList/CMap and its subclass-encapsulate the corresponding data structure in C ++

15. Non-CObject class-encapsulated operations on various structures

Example: CPoint, CRect, CString, CTime...

V. The Class Wizard function of MFC (ClassWizard)

On the menu bar of VC6, choose View> Create Class Wizard (Ctrl + W)

  

1. Message Maps Tab

① Project: the name of the current Project is displayed in the drop-down list box. In fact, for VC ++, a workspace (. dsw) can contain multiple projects (. dsp ). Therefore, if there are multiple projects in the workspace, you can select the Project to be processed from the Project drop-down list box.

② Class name: the drop-down list box displays the classes contained in the current project. You can select any classes that exist in the current project and add message processing functions to them.

③ Object IDs: The list box lists the IDs of all resources in the selected class, including menu items and dialog box controls. The first item in the list is always the current class name.

④ Messages: the list box lists the Messages that can be processed for the current item selected in the Object IDs box, And the MFC virtual functions that can be overwritten for the current class.

⑤ Member functions: the list box lists all Member functions contained in the current class. Specifically, virtual functions are marked with the character "V" and Windows message processing functions are marked with the character "W.

⑥ Add Class: the button allows you to Add a new Class to the project. The new class can be created by yourself or selected from the ActiveX library.

7. Add Function: the button allows you to Add a new message processing Function or overload the virtual Function of the base class to the Member Functions list box.

Revoke Delete Function: the button allows you to Delete the Function selected in the Member Functions list box.

Edit Code: click the button to open the Edit window. You can Edit the selected items in the Member Functions box.

  

2. Member Variables Tab

① Project: the drop-down list box has the same meaning as the Project drop-down list box on the Message Maps tab. The current Project name is displayed.

② Class name: the drop-down list box is the same as the Class name drop-down list box on the Message Maps tab. The classes contained in the current project are displayed. You can select the classes to be operated from the drop-down list box.

③ Control IDs: ID of the Control in the displayed dialog box; Type indicates the Type of the Member variable; Member indicates the name of the Member variable.

④ Add Class: the button allows you to Add a new Class to the project. The new class can be created by yourself or selected from the ActiveX library.

⑤ Add Variable: the button is used to Add member variables to the selected control.

⑥ Delete Variable: the button is used to Delete the member variables of the selected control.

7. Update Columns: the button is used to Update the corresponding record set class when the table structure in the data source changes, so as to be consistent with the latest table structure.

Sort Bind All: the button is used to Bind fields in the specified table in the database to the corresponding data members of the record set class one by one. By default, ClassWizard determines the name of the corresponding data member in the record Class Based on the name of each field.

3. Automation Tab

① Project: the name of the current Project is displayed in the drop-down list box.

② Class name: the drop-down list box displays the classes contained in the current project. You can select any classes that exist in the current project, including those that do not support Automation.

③ External names: list the External names of the methods and attributes that have been added to the current class. These names are used by the Automation client program.

④ Implementation: the text box shows how the methods and attributes selected in the External names box are implemented in the C ++ class: S indicates the inherent attributes, C indicates the custom attributes, and M indicates the methods, bold indicates the default attribute.

⑤ Add Class: the button allows you to Add a new Class to the project. The new class can be created by yourself or selected from the ActiveX library.

⑥ Add Method: the button is used to Add a new Automation Method to the class. When a method is added or deleted, Class Wizard automatically updates the ing table. This option is only valid for classes that support Automation.

7. Add Property: the button is used to Add a new Automation Property to the class. When adding or deleting properties, Class Wizard automatically updates the ing table. This option is only valid for classes that support Automation.

Revoke Delete: Delete the method or attribute name selected in the External names box. If the attribute is accessed in Get/Set mode, you must manually delete the Get and Set member functions in the. cpp file.

Edit Code: click the button to open the Edit window.

Custom Data Binding: Specifies the Data Binding level supported by the Automation control.

  

4. ActiveX Events Tab

① Project: the name of the current Project is displayed in the drop-down list box.

② Class name: the drop-down list box displays the classes contained in the current project. You can select any classes that exist in the current project, including those that do not support ActiveX.

③ External names: List lists member functions and member variable names that have been added to the current class. These names are used by the Automation client program.

④ Implementation: The Implementation of the methods and attributes selected in the External names box displayed in the text box in the C ++ class: S indicates the inherent attributes, C indicates the custom attributes, and M indicates the methods, bold indicates the default attribute.

⑤ Add Class: the button allows you to Add a new Class to the project. The new class can be created by yourself or selected from the ActiveX library.

⑥ Add Event: the button allows you to Add Automation events. This event is used for communication between classes and containers of this type.

7. Delete: the button is used to Delete the selected Automation event.

  

5. Class Info tab

① Project: the name of the current Project is displayed in the drop-down list box.

② Class name: the drop-down list box shows the classes contained in the current project. You can select the class to be processed.

③ File details: displays the File and resource ID of the current class.

④ Advanced options: the control group includes:

Message filter: the drop-down list box lists all types of messages that are valid for the selected class. The categories are classified by the Message window or dialog box type.

Foreign class: the content of the drop-down list box is determined by the type of the selected class. If the currently selected class is a dialog box, formatted view, or record set view, this box lists all external class names associated with the selected class. In other cases, None is displayed.

Foreign variable: box lists all external variables related to the currently selected class. This option is generally used for database classes. When editing the record set view, you can select the relevant record set and enter a new variable name.

⑤ Add Class: the button is used to Add a new Class.

 

Related Article

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.