Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Suppressing accelerator keys temporarily

Suppressing accelerator keys temporarily

Scheduled Pinned Locked Moved C / C++ / MFC
data-structureshelpquestion
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Graham Shanks
    wrote on last edited by
    #1

    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!

    G 1 Reply Last reply
    0
    • G Graham Shanks

      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!

      G Offline
      G Offline
      Graham Shanks
      wrote on last edited by
      #2

      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!

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups