Domanda

I'd like to assign an accelerator key to a menu item that doesn't have an accelerator key while running in C++ and be able to change it. I've looked through the docs and MSDN and it isn't clear to me how this can be done.

È stato utile?

Soluzione

You need to manage your own accelerator table.

You can create a resource table from an array of ACCEL structs, populating and passing them to CreateAcceleratorTable. Or you can load them from resources via LoadAccelerators. This gives you an HACCEL handle. In your main message loop use this HACCEL handle in the TranslateAccelerator call.

When it comes time to edit the accelerators, if you don't have the ACCEL array around anymore, call CopyAcceleratorTable with the HACCEL handle to get the ACCEL array back. Edit this array as needed, then recreate a new HACCEL handle with CreateAcceleratorTable and delete the old one. Use this new handle for accelerators until the next change.

Your WndProc will get the messages for these accelerators. In the message handler call the implementation for the menu action handler.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top