Microsoft KB Archive/110800

= FIX: CEditView in Splitter Window Doesn't Update Document =

Article ID: 110800

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.0 Professional Edition 

-

<div class="notice_section">

This article was previously published under Q110800

<div class="symptoms_section">

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.

<div class="cause_section">

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.

<div class="resolution_section">

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.

<div class="status_section">

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.

<div class="moreinformation_section">

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

<div class="references_section">