Save and modify a document: how to display a "modified" asterisk * in the attempted title and associate it with a "modified" document?

Source: Internet
Author: User

The general solution to this problem can be like "3.20 how to customize the view title ?" . If you only want to display a simple "modified" indicator. For example, if there is a '*' in the title of a "modified" document, you only need to simply reload the cdocument: setmodifiedflag () function, no matter when the document object is changed, you can call this function.

We can safely reload setmodified (), because this function is declared as a virtual function in the cdocument class. Although visual c ++'s online help forgot to mention this fact.

The following program list illustrates the implementation of setmodified (). When the document becomes "changed", it modifies the document title and attaches '*', when the document is changed to "saved" again, it is usually because the user saves the modified document and moves this '*'.

Note that the extra space before '*' is required. It prevents MFC from processing the asterisk as part of the document name. Finally, you must manually reload setmodified () without the help of classwizard ().

[CPP]
View plaincopyprint?
  1. Virtual void setmodifiedflag (bool bmodified );
  2. Void cdrawdoc: setmodifiedflag (bool bmodified)
  3. {
  4. Cstring strtitle = gettitle ();
  5. // Note: the space before the "modified" identifier
  6. // It prevents file name problems in the "Save as" dialog box
  7. Cstring strindicator = "*";
  8. If (! Ismodified () & bmodified)
  9. {
  10. // 1. The document was previously "not modified", and now "modified"
  11. Settitle (strtitle + strindicator );
  12. }
  13. Else if (ismodified ()&&! Bmodified)
  14. {
  15. // 2. The document was previously "modified" and is now "unmodified"
  16. Settitle (strtitle. Left (strtitle. getlength ()-strindicator. getlength ()));
  17. }
  18. // Force update the title of the Framework Window (this will display a new title in the Framework Window)
  19. Updateframecounts ();
  20. // Finally, call the standard function
  21. Cdocument: setmodifiedflag (bmodified );
  22. }

Virtual void setmodifiedflag (bool bmodified); <br/> void cdrawdoc: setmodifiedflag (bool bmodified) <br/>{< br/> cstring strtitle = gettitle (); <br/> // note: "modified" the space before the logo <br/> // It prevents problems with the document name in the "Save as" dialog box <br/> cstring strindicator = "*"; <br/> If (! Ismodified () & bmodified) <br/>{< br/> // 1. The document was "not modified ", it is now "modified" <br/> settitle (strtitle + strindicator); <br/>}< br/> else if (ismodified ()&&! Bmodified) <br/>{< br/> // 2. The document was previously "modified" and is now "unmodified" <br/> settitle (strtitle. left (strtitle. getlength ()-strindicator. getlength (); <br/>}< br/> // force update the title of the Framework Window (this will display a new title in the Framework Window) <br/> updateframecounts (); <br/> // Finally, call the standard function <br/> cdocument: setmodifiedflag (bmodified); <br/>} 

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.