FIX: CEditView in Splitter Window Doesn't Update Document

ID: Q110800


The information in this article applies to:
  • The Microsoft Foundation Classes (MFC), included with:
    • Microsoft Visual C++ for Windows, 16-bit edition, versions 1.0, 1.5
    • Microsoft Visual C++, 32-bit Editions, version 1.0


SYMPTOMS

Normally, when the text in a CEditView object is changed, it sets the modified flag of the document to which it is attached. If you try to close the last view on the document or exit the application without saving, you will be prompted to save the data.

When the CEditView derived class is a pane in a splitter window, the modified flag is not set when the text changes.


CAUSE

CEditViews are themselves edit controls. This means the notification messages are sent to the parent of the CEditView.

When you don't have a splitter window, the CEditView is created as a child of a class that is derived from CFrameWnd. A part of the command routing of CFrameWnd is to send the message to the active view (in this case the CEditView message) by calling the view's OnCmdMsg() member function. CEditView then handles the EN_CHANGE notification message by setting the modified flag of the document.

When you use a splitter window, the CEditView message is a child of CSplitterWnd. CSplitterWnd is derived from CWnd but not CFrameWnd. CWnds do not send messages back to views as CFrameWnds do, so the message is not passed back to the CEditView and the modified flag isn't set.


RESOLUTION

In both cases the parent window of the CEditView calls the CEditView's OnChildNotify() member function when it receives the EN_CHANGE notification message. The workaround is to add an OnChildNotify() member function to a CEditView derived class (called CMyEditView for the sample below).

The sample code shows the definition of the OnChildNotify() function. You will also need to add a declaration for OnChildNotify() to your class declaration.


STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This bug was corrected in MFC 3.0, included with Visual C++ 2.0.


MORE INFORMATION

The name of the view class (CMyEditView) in the sample code below is for purposes of discussion only. You should replace this with the name of your own view class that you have derived from CEditView.

There are some differences in the way message parameters are "packed" into wParam and lParam between 16-bit Windows and Win32. These differences are handled in the sample code using conditional compilation based on the _WIN32 symbol. This symbol is automatically defined by the 32-bit version of Visual C++.

SAMPLE CODE


/*
** This is a code fragment only and will not compile as is. Please see
** the MORE INFORMATION section above.
*/ 
BOOL CMyEditView::OnChildNotify( UINT message,
   WPARAM wParam,
   LPARAM lParam,
   LRESULT* pLResult )
{
   WORD wNotification;
#ifdef _WIN32
   wNotification = HIWORD(wParam);
#else
   wNotification = HIWORD(lParam);
#endif
   if (message == WM_COMMAND && wNotification == EN_CHANGE)
   {
      CEditView::OnEditChange();
      return TRUE;
   }
   else
      return FALSE;
} 


REFERENCES

For more information on command routing, refer to the "Class Libraries Reference" of the Microsoft Visual C++ documentation, or the online help for CWnd::OnChildNotify.

Additional query words: 1.00 1.50 2.00 2.10 2.50 SetModifiedFlag CDocument

Keywords : kbMFC KbUIDesign kbVC
Version : 1.00 1.50 | 1.00
Platform : NT WINDOWS
Issue type :


Last Reviewed: September 10, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.