Visual C ++. Net foundation lecture

xiaoxiao2021-03-06  107

Second lecture reading and display of document data

Summary

This clarity first introduces the association mechanisms of the procedures, then discuss the read procedures and read operations of the document, and finally discuss the display methods and techniques of document data. Association of each user class in the program

In the previous talk, we use the MFC Application Wizard to create a single document item TextViewer. Now we open the project. It can be seen that the wizard creates the following classes to the TextViewer project:

Application class ctextViewerapp, the application must have a running entry, which has been discussed.

The main frame window CMAINFRAME is used to operate the interface elements such as the title bar, menu, toolbar, and status bar.

Document class ctextViewerDoc, is used to read and save document data

View class CTextViewerView class, used to display document display and can respond to various types of inputs (such as keyboard input), and implement print and print previews.

There is also a dialog box CaboutDLG to display version information of the application, which is a "About" dialog.

It should be noted that Visual C .NET saves the declarations of each class in the header file, which is the extension of the class to the extension of the class with .cpp as the extension of the extension.

So, what is the relationship between the main frame window, document class and view classes in the MFC? Let's take a look.

Switch the Solution Manager to "Class View", expand all nodes of the CTextViewRAPP class, double-click "InitInstance (Void)" to open the function code. Since the code comment for Visual C .NET is Chinese, we only give the code as shown in Figure 1 here.

Figure 1 Some of the code in the initInstance function

In the code, CSINGLEDOCTemplate is a single document class derived from CDOCTemplate, which coordinates the relationship between document windows, documents, and views, and linked three. The constructor of this class needs to specify four parameters, which represent the resource ID number indicating the menu and acceleration keys, respectively, and three CruntimeClass structural object pointers specified by macro runtime_class, which are the program's document class, frame window, and view classes, respectively. The structural pointer.

The CruntimeClass structure reflects a runtime class, usually with macro runtime_class to get a class of CRUNTIMECLASS structural pointers. Visual C can get information about this class object and its base class during the application running process, so that the runtime type check can be implemented (Run Time Type Inspection, RTTI).

AddDoCtemplate is used to add the specified single document template or multi-document template pointer to the document template pointer list included in the program.

转载请注明原文地址:https://www.9cbs.com/read-97276.html

New Post(0)