FIX: CEditView in Splitter Window Doesn't Update DocumentLast reviewed: September 18, 1997Article ID: Q110800 |
1.00 1.50 | 1.00
WINDOWS | WINDOWS NTkbprg kbfixlist kbbuglist The information in this article applies to:
SYMPTOMSNormally, 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.
CAUSECEditViews 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.
RESOLUTIONIn 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.
STATUSMicrosoft 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 INFORMATIONThe 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;}
REFERENCESFor 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 reference words: 1.00 1.50 2.00 2.10 2.50
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |