Link to home
Start Free TrialLog in
Avatar of marcus78
marcus78

asked on

Programatically disable an accelerator key (then re-enable it later)

Hi - I've got an accelerator defined so that a commonly used menu item is fired when the user presses the space bar.  At times, I'd like to disable it, then reenable it at a later point. How can I do this? The accelerator is defined under IDR_MAINFRAME.

Thanks,
Marcus
Avatar of ShaunWilde
ShaunWilde

why not use a simple flag that you put in the handler for the space bar being pressed.

eg pseudocode

OnSpacebar() // okay not a proper handler but you get the drift
{
  if (bProcess)
  {
    // do menu action
  }
}
Avatar of marcus78

ASKER

Hi - it's not quite a simple as that.  The accelerator is mapped to a function in my document class.  In one of my views, i have a list control where the user can edit some text.  The problem is that when i start editing the text, if i press the space bar, (to actually put a space in the text i'm typing), the handler in the document is fired before it gets to the view. so once the document handles it, even if i use the code below, the space character is stifled before it gets to the view. Hence, the space character won't show up.  So, if i can disable the accelerator when the user begins editing the item in the list control, the message won't get sent to the document.

At least, this is my take on it.  Can you think of anything else?

Thanks,
Marcus
Hi
why don't u try using Hook key methods where in u can provide ur own functionality and as well retain the standard feature. Try searching in MSDN for hook key's u will find some samples there.
Hope it helps u.
-shilpa
Shilpa - Will do.  I'll try this out and get back to you.

Thanks!
how do you edit the text in a list control? - In my xperience a hook should be the last resort not the first
you could also use pretranslate message
ASKER CERTIFIED SOLUTION
Avatar of ShaunWilde
ShaunWilde

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Shilpa - I agree with ShaunWilde - after reading about it some more, a hook seems rather much for this.

ShaunWilde - this sounds like what I'm looking for.  I'll give it a go, and get back to you soon.  Thanks!

Marcus
> I'll give it a go, and get back to you soon

the project I used to get this solution was an MFC SDI app with a ListView as the CView derived class
ShaunWilde - That's exactly what I needed.  That solved my problem completly!

Thanks,
Marcus
okay :)