How to change the default document operation mode of MFC

Source: Internet
Author: User

How to change the default document operation mode of MFC

When MFC is used for programming, its document/view structure automatically generates new, open, and saved code for the file. This saves us a lot of trouble. But when the operation object is non-text files such as ODBC databases, the problem arises. How can I change the default document operation process?

After analyzing the source code of MFC, we can see that. The "New" "open" message in the default menu corresponds to the cwinapp: onfilenew () and cwinapp: onfileopen (), and the two functions directly call cdocmanager :: onfilenew and cdocmanager: onfileopen. Cdocmanager: onfileopen works as follows:

1. Call cdocmanager: dopromptfilename, while dopromptfilename is used to display the file opening dialog box to obtain the file name.

2. Call cwinapp: opendocumentfile (lpctstr lpszfilename ).

To change the document opening method, you only need to reload dopromptfilename and opendocumentfile in the inheritance class of cwinapp. For example, to change the default file opening dialog box. You only need to create a file to open the dialog box and call it in the overloaded dopromptfilename to get a file name.

The following is an analysis of cwinapp: opendocumentfile. The working process of opendocumentfile is:

1. Determine which document template to use by the suffix of the parameter lpszfilename.

2. Adjust the document, view, and framework windows of the document template.

3. Call cdoctemplate: opendocumentfile

Cdoctemplate: opendocumentfile is a pure virtual function, which is implemented by its derived classes csingledoctemplate and cmultidoctemplate. It is illustrated by csingledoctemplate: opendocumentfile.

1. Determine whether there are existing documents. If yes, determine whether the documents have been saved.

2. Create a Framework Window.

3. Check whether the file exists by the file name path. If yes, call the custom cmydoc: onopendocument. Otherwise, call cmydoc: onnewdocument.

From the above analysis, we can make multiple changes to the default file operation method of MFC, such as changing the file opening and saving mode and changing the file opening and saving dialog box.

The various source codes shown above can be obtained from the mfcinclude and mfcsrc subdirectories under the VC installation directory. Cwinapp, cdocmanager, and csingledocmanager. the header file of the cdocument class is afxwin. h. The source code of the cwinapp class is in appcore. in CPP, the source code of cdocmanager is in docmgr. in CPP, the source code of the cdoctemplate class and csingledocmanager class are located in doctempl. CPP and docsingl. CPP.

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.