VC ++ technical insider (Fourth Edition) Note (chapter 2)

Source: Internet
Author: User

/*************************************/

Chapter 2: Reading and Writing documents-MDI applications

1. The cmdiframewnd class in the MFC Library encapsulates all the functions of the main framework window and the MDI customer window (including the message control functions of all windows MDI messages ), therefore, you can manage its subwindows (represented by javasichildwnd class objects ).

2. In an MDI application, only one subwindow is active at any time. The MDI application only uses menus and toolbar, and all commands on it are passed to the current active subwindow. The file name of the active window is displayed in the title bar of the main window.

3. Most MDI applications have the same startup sequence as SDI applications. The initinstance function that is overloaded by the derived class in MDI is different from that in SDI. (For details about different tracking codes, refer to page 362. I will not copy them)

4. MDI Application essence: An MDI application can use multiple document types and allow more than one document object to exist at the same time.
Comparison:
SDI:
Csingledoctemplate * pdoctemplate;
Pdoctemplate = new csingledoctemplate (
Idr_mainframe,
Runtime_class (cstudentdoc ),
Runtime_class (cmainframe), // main SDI frame window
Runtime_class (cstudentview ));
Adddoctemplate (pdoctemplate );

In MDI:
Cmultidoctemplate * pdoctemplate;
Pdoctemplate = new cmultidoctemplate (
Idr_ex17atype,
Runtime_class (cstudentdoc ),
Runtime_class (cchildframe), // custom MDI child frame
Runtime_class (cstudentview ));
Adddoctemplate (pdoctemplate );
// The call of adddoctemplate (pdoctemplate) in MDI enables the MDI application to support multiple subwindows, and each subwindow is connected to a document object and a view object. Several subwindows (and their corresponding view objects) may also be connected to a document object.
// MDI dynamically creates a cchildframe object.

5. SDI can only have one frame window class and one frame window object (cmainframe: cframewnd). The MDI application has two frame window classes and multiple Frame Objects, namely:
Cmainframe: cmdiframewnd has only one corresponding object with menus and control columns without views.
Cchildframe: cmdichildwnd each subwindow corresponds to an object with no menu and a view in the control bar.
Object creation: the cmainframe object is in the initinstance function of the application class (that is, cmainframe * pmainframe = new cmainframe;); The cchildframe object is when a new subwindow is opened, created by the application framework (call of processshellcommand in the initinstance function in MDI is used to create a sub-framework ).

6. The initinstance function of MDI sets cwinapp: m_pmainwnd to the main frame window pointer pointing to the application. Therefore, m_pmainwnd can be accessed at any time through the afxgetapp function.

7. An MDI program contains two independent string resources, which are identified by idr_mainframe and idr_ex17atype (depending on Project changes. (See P361-362 for details)

8. Create a new document and create a new view for the existing document. (For details, refer to page 362. Many terms are not copied)

9. Each time a document file is loaded from a disk, the MDI application constructs a new document object. When the subwindow is closed, the corresponding document object is deleted. (Problem: if multiple subwindows are connected to the same document object, will the associated document object be deleted when a subwindow is closed ?)

10. Multiple adddoctemplate calls are not supported in SDI (document objects, view objects, and framework objects are created only once during the life cycle of an application in SDI ), in MDI, adddoctemplate is called multiple times to support multiple document templates. Each template can be used to create a combination of different document classes, view classes, and MDI sub-framework classes.

(Note: The notes in this chapter are a little rough. The instance only looks at the code that has not been tracked, and then finds a good instance to make up the time relationship. The notes are paused for some time. Sorry)
/////////////////////////

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.