How to Detect If a CFormView Has Changed

Last reviewed: October 10, 1997
Article ID: Q133307
1.00 1.50 1.51 1.52 | 2.00 2.10 2.20 4.00 4.10
WINDOWS             | WINDOWS NT
kbprg kbui

The information in this article applies to:

- The Microsoft Foundation Classes (MFC) included with:

   - Microsoft Visual C++ for Windows, versions 1.0, 1.5, 1.51, 1.52
   - Microsoft Visual C++, 32-bit Edition, versions 2.0, 2.1, 2.2, 4.0, 4.1

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 reference 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
KBCategory: kbprg kbui
KBSubcategory: MfcDocView
Keywords : MfcDocView kbprg kbui
Technology : kbMfc
Version : 1.00 1.50 1.51 1.52 | 2.00 2.10
Platform : NT WINDOWS


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: October 10, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.