How to add accelerator key in MFC project with ribbon interface

Locked How to add accelerator key in MFC project with ribbon interface

  • Thursday, July 26, 2012 5:22 AM
     
     

    Use App wizard create a MFC project with ribbon.
    Some of accelerators are working well(Ctrl+X, Ctrl+C...).
    I add a new accelerator like Del key in Accelerator editor,
    but it did not work.
    Ribbon interface does not use accelerator table in the resource?
    How can I add new accelerator key for my ribbon project?


    Sunyear

All Replies

  • Thursday, July 26, 2012 8:30 AM
     
     

    Use App wizard create a MFC project with ribbon.
    Some of accelerators are working well(Ctrl+X, Ctrl+C...).
    I add a new accelerator like Del key in Accelerator editor,
    but it did not work.

    It's possible that the Delete key is being handled specially somewhere
    - try something less conspicuous  like Ctrl+G as an accelerator and
    see if that works.

    Dave

  • Thursday, July 26, 2012 9:09 AM
     
     

    Use App wizard create a MFC project with ribbon.
    Some of accelerators are working well(Ctrl+X, Ctrl+C...).
    I add a new accelerator like Del key in Accelerator editor,
    but it did not work.

    It's possible that the Delete key is being handled specially somewhere
    - try something less conspicuous  like Ctrl+G as an accelerator and
    see if that works.

    Dave

    Thank for your answer.
    Yes, I had try another key like Ctrl+D, It also did not work :(
    On other project without ribbon, just add new accelerator key in the accelerator table, then the key work well.
    I traced the code, the accelerator table had loaded in the main frame like the other projects.
    I guess the ribbon snatched the key translation routing.



    Sunyear

  • Thursday, July 26, 2012 9:37 AM
     
     Answered

    Yes, I had try another key like Ctrl+D, It also did not work :(
    On other project without ribbon, just add new accelerator key in the accelerator table, then the key work well.
    I traced the code, the accelerator table had loaded in the main frame like the other projects.
    I guess the ribbon snatched the key translation routing.

    I have a vague recollection that newer MFC projects persist the
    accelerators to the registry, so I wonder if the changes done in your
    resource are being discarded later in initialisation in favour of
    saved settings?

    Dave

    • Marked As Answer by Sunyear Huang Friday, July 27, 2012 3:44 AM
    •  
  • Friday, July 27, 2012 3:43 AM
     
     

    I have a vague recollection that newer MFC projects persist the

    accelerators to the registry, so I wonder if the changes done in your
    resource are being discarded later in initialisation in favour of
    saved settings?

    Dave

    Yes, I found a related document that mention this issue.
    MFC(from VS2008) uses CKeyboardManager object to manage accelerators.
    The resource's accelerator table still work but the state will be replaced by the registry's reserve. 
    Use CKeyboardManager::UpdateAccelTable or CKeyboardManager dialog can reset to resource setting.
    thanks again!


    Sunyear