The information in this article applies to:
SYMPTOMSWhen you edit labels in a CTreeCtrl, you are allowed to press the ESC key to cancel the changes or press the ENTER key to accept the changes. However, when the CTreeCtrl is a child window of a dialog box (CDialog), a formview window (CFormView), or a property page (CPropertyPage), the ESC or ENTER keys do not function as expected. CAUSEIsDialogMessage() function is called in the PreTranslateInput() function which in turn is called in the PreTranslateMessage() function of all CFormView or CDialog derived classes mentioned above. The ESC and ENTER keys are processed in IsDialogMessage() but are not passed on to the edit control created by the tree-view control. Thus, these keystrokes have no effect. RESOLUTION
For Visual C++ 4.xx and later, we can trap the ESC and ENTER keystroke
messages in the PreTranslateMessage() function for all CFormView, CDialog
(modal or modeless) and CPropertyPage (either in modal or modeless
CPropertySheet) derived classes.
For Visual C++ 2.xx, since PreTranslateMessage() is not called for modal
CDialog-derived classes, the sample code above does not apply to the modal
dialog and property page in a modal CPropertySheet derived class. In this
situation, those keystroke messages can be trapped in the overridden OnOK()
(for Enter key) and OnCancel() (for Esc key) functions in either CDialog or
CPropertySheet derived-class. The sample code works fine even in the
absence of both the OK and Cancel buttons from the dialog resource
template.
NOTE: It is too late to trap those keystroke messages in CPropertyPage's OnOK() and OnCancel() functions. Therefore, we have to do it in CPropertySheet-derived class. A new member function called IsTreeCtrlEditMessage() is added to the CDialog or CPropertySheet derived-class. This function sends a WM_KEYDOWN message to the tree-view's edit control when it is the window with focus. And it is being called in both overridden OnOK() and OnCancel() functions. The CMyDxxx in the sample code below can either be a CDialog or a CPropertySheet derived-class. Note that the MODAL_PROPERTYSHEET constant is declared and used in IsTreeCtrlEditMessage() so the same code can be applied to both CDialog and CPropertySheet derived-classes.
STATUSMicrosoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. MORE INFORMATIONFor more information about CTreeCtrl, please refer to the MFC online help and Win32 SDK help files. REFERENCESFor additional information, please see the following article in the Microsoft Knowledge Base: Q130691 BUG: ESC/ENTER Keys Don't Work When Editing Labels in TreeView(c) Microsoft Corporation 1997, All Rights Reserved. Contributions by Yeong-Kah Tam, Microsoft Corporation © Microsoft Corporation 1997, All Rights Reserved.
Keywords : kbui kbMFC KbUIDesign kbVC kbVC200bug kbVC210bug kbVC220bug kbVC400bug kbVC410bug kbVC420bug kbVC500bug kbVC600bug |
Last Reviewed: July 23, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |