Microsoft KB Archive/133307

= HOWTO: How to Detect If a CFormView Has Changed =

Article ID: 133307

Article Last Modified on 11/21/2006

-

APPLIES TO

 Microsoft Foundation Class Library 4.2, when used with:  Microsoft Visual C++ 1.0 Professional Edition

 Microsoft Visual C++ 1.5 Professional Edition

 Microsoft Visual C++ 1.51

 Microsoft Visual C++ 1.52 Professional Edition</li></ul>

 Microsoft Visual C++ 2.0 Professional Edition</li></ul>

 Microsoft Visual C++ 2.1</li></ul>

 Microsoft Visual C++ 2.2</li></ul>

 Microsoft Visual C++ 4.0 Standard Edition</li></ul>

 Microsoft Visual C++ 4.1 Subscription</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q133307

<div class="summary_section">

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.

<div class="moreinformation_section">

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 kbhowto kbnoupdate KB133307

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.