Ans: While working in a VC++ source editor if you observe carefully, you would see that if you make any changes in a file an indicator in the form of an asterisk ( ‘*’ ) is shown in the title bar indicating that the file is modified. If you save the file the indicator disappears. We can also display such an indicator and remove it if user saves the document, by simply overriding a virtual function SetModifiedFlag( ) in the document class as shown below:
void CTitleDoc::SetModifiedFlag ( BOOL bmodified )
{
CString title = GetTitle( ) ;
CString indicator = ” *” ;
if ( !IsModified( ) && bmodified )
SetTitle ( title + indicator ) ;
else
{
if ( IsModified( ) && !bmodified )
{
title = title.Left ( title.GetLength( ) – indicator.GetLength( ) ) ;
SetTitle ( title ) ;
}
}
CDocument::SetModifiedFlag ( bmodified ) ;
}
Note that you must manually override the SetModifiedFlag( ) function without the help of ClassWizard because although SetModifiedFlag( ) is a virtual function it is not mentioned in the online help and if you right click the document class in ClassView tab and select ‘Add Virtual function’ you would not see this function in the list of virtual functions.