Suppressing accelerator keys temporarily
-
My application has a CFrameWnd which contains a CTreeCtrl. So that the user can easily delete an element from the tree I have set up an accelerator so that the Delete key issues an ID_EDIT_DELETE command. So far so good. The problem comes when I want to do an inline edit of an element in the tree. The delete key is still issuing the ID_EDIT_DELETE command - I can stop it deleting the element by putting a guard set between the TVN_BEGINLABELEDIT and TVN_ENDLABELEDIT events. But this is not a behaviour that I want. I want the delete key to act as normal during the label editing. Is there any way to temporarily suppress the accelerator keys during label editing?
Graham Librarians rule, Ook!
-
My application has a CFrameWnd which contains a CTreeCtrl. So that the user can easily delete an element from the tree I have set up an accelerator so that the Delete key issues an ID_EDIT_DELETE command. So far so good. The problem comes when I want to do an inline edit of an element in the tree. The delete key is still issuing the ID_EDIT_DELETE command - I can stop it deleting the element by putting a guard set between the TVN_BEGINLABELEDIT and TVN_ENDLABELEDIT events. But this is not a behaviour that I want. I want the delete key to act as normal during the label editing. Is there any way to temporarily suppress the accelerator keys during label editing?
Graham Librarians rule, Ook!
Solved it thanks to a colleague. I need to override the PreTranslateMessage message in my tree control class (it was already subclassed so that it wasn't a problem) as follows:
BOOL MyTreeCtrl::PreTranslateMessage(MSG* pMsg)
{
if( pMsg->message == WM_KEYDOWN )
{
// When an item is being edited make sure the edit control
// receives certain important key strokes
if( GetEditControl() &&
(pMsg->wParam == VK_RETURN
|| pMsg->wParam == VK_DELETE
|| pMsg->wParam == VK_ESCAPE
|| GetKeyState(VK_CONTROL)))
{
::TranslateMessage(pMsg);
::DispatchMessage(pMsg);
return TRUE; // DO NOT process further
}
}return CTreeCtrl::PreTranslateMessage(pMsg);
}Graham Librarians rule, Ook!