sg_man sg_man - 3 months ago 32
C++ Question

MFC "Hidden" or "Default" Function Key Accelerators?

I have a pretty normal MFC SDI application.

I recently started using things from the new MFC feature pack (eg CMFCToolbar), and after all these changes, I am seeing some unexplained behavior in keyboard shortcuts.

It seems some resource IDs have function key shortcuts (like F6), but I cannot find out how this works, or how to disable it.

For example, if I mouseover ID_ABC in a toolbar, I see a tooltip like:

ABC (F2)
Do ABC action

I don't see VK_F2 anywhere in the accelerator table, or anywhere at all for that matter. I also cannot find (F2) anywhere at all in the solution. This all seems very weird to me. Pressing F2 does indeed do ABC.

If I delete the entire accelerator table, that seems to "fix" the problem, but then of course I have no accelerators. As soon as I add any accelerator back, the problem re-appears.

Usually, when I run into these things, I seem to be on my own, and the cause of the problem is usually "far away", sort of like landing in some random function after a bad memory access, and saying, "why am I here"??

But if anyone knows anything about this, thanks!


Just look into the accelerator table in the resource file of your application. Yes, many standard commands do have accelerator keys assigned (eg Ctlr+S is mapped to the File Save command). You can delete the commands you do not want (individually, not the whole accelerator table). The application "remembering" the old accelerator table assignments (or not working with the new ones) may be due to saving these in the registry. Go there and delete the "Workspace" tree for your application, and then test anew.

Menu item labels must contain the shortcut as well, separated by a tab (eg File &Open\tCtlr+O). Status bar hints and tooltips are created by a string resource, with the same ID as the menu or toolbar item. You can create/edit these in the Menu Editor or the String Table Editor. The two items are separated by a newline character.