How to Detect If a CFormView Has Changed

ID: Q133307


The information in this article applies to:


SUMMARY

Changes to the controls on a CFormView-derived class are not automatically detected by the framework. As in any other CView-derived class, it is up to your view to let the document know when its content has changed.


MORE INFORMATION

When the content of a control on a CFormView-derived class has changed, the document associated with the view should be marked as modified. Doing this results in MFC popping up a dialog box asking the user if they want to save the changed file whenever the user tries to either close the application or load a different document.

To mark a document associated with a CFormView-derived class as modified, add OnChange handlers for the controls on the view, and call the CDocument class member function SetModifiedFlag(TRUE). For example, for an edit control, add a handler for the EN_CHANGE message in the CFormView-derived class, and call GetDocument()->SetModifiedFlag(TRUE).

The number of controls for which the programmer should provide OnChange handlers depends on the extent to which the application serializes the UI state of CFormView. For example, if the current selection of a listbox is serialized, then a change in the listbox item selection should be considered a change to the document.

For controls like a group of option buttons, add handlers for the BN_CLICKED message in the CFormView-derived class, and if the button selection has changed, call GetDocument()->SetModifiedFlag(TRUE).

Additional query words: kbinf 1.00 1.50 2.00 2.10 2.20 2.50 2.51 2.52 3.0 3.00 3.1 3.10 3.2 3.20 4.00 4.10


Keywords          : kbDocView kbMFC kbVC 
Version           : 1.00 1.50 1.51 1.52 | 2.00 2.10
Platform          : NT WINDOWS 
Issue type        : 

Last Reviewed: July 27, 1999