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?
- Virtual void setmodifiedflag (bool bmodified );
- Void cdrawdoc: setmodifiedflag (bool bmodified)
- {
- Cstring strtitle = gettitle ();
- // Note: the space before the "modified" identifier
- // It prevents file name problems in the "Save as" dialog box
- Cstring strindicator = "*";
- If (! Ismodified () & bmodified)
- {
- // 1. The document was previously "not modified", and now "modified"
- Settitle (strtitle + strindicator );
- }
- Else if (ismodified ()&&! Bmodified)
- {
- // 2. The document was previously "modified" and is now "unmodified"
- Settitle (strtitle. Left (strtitle. getlength ()-strindicator. getlength ()));
- }
- // Force update the title of the Framework Window (this will display a new title in the Framework Window)
- Updateframecounts ();
- // Finally, call the standard function
- Cdocument: setmodifiedflag (bmodified );
- }
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/>}