Article ID: 130691 - View products that this article applies to.
This article was previously published under Q130691
When you edit labels in a TreeView control, you should be able to press the ESC key to cancel the changes or press the ENTER key to accept the changes. However, when the TreeView control is contained in a dialog box, IsDialogMessage processes the ESC and ENTER keystrokes and does not pass them on to the edit control that is created by the TreeView control. The result is that the keystrokes have no effect.
The tree view control creates and subclasses the edit control that is used for in-place editing. The subclass procedure does not handle the WM_GETDLGCODE message that is sent by IsDialogMessage, which results in default handling of the keystrokes by IsDialogMessage.
To work around this problem, subclass the edit control in response to the TVN_BEGINLABELEDIT notification that is sent by the tree view control when the tree view is about to start label editing for an item. To obtain the edit control's window handle, send the tree view control a TVM_GETEDITCONTROL message.
The subclass procedure should handle the WM_GETDLGCODE message by returning DLGC_WANTALLKEYS. This allows the tree view's subclass procedure to handle ESC and ENTER keystrokes.