CMFCAcceleratorKey Class
The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.
The latest version of this topic can be found at CMFCAcceleratorKey Class.
A helper class that implements virtual key mapping and formatting.
class CMFCAcceleratorKey : public CObject
Public Constructors
| Name | Description |
|---|---|
| CMFCAcceleratorKey::CMFCAcceleratorKey | Constructs a CMFCAcceleratorKey object. |
Public Methods
| Name | Description |
|---|---|
| CMFCAcceleratorKey::Format | Translates the ACCEL structure to its visual representation. |
| CMFCAcceleratorKey::SetAccelerator | Sets the shortcut key for the CMFCAcceleratorKey object. |
Accelerator keys are also known as shortcut keys. If you want to display keyboard shortcuts that a user enters, the CMFCAcceleratorKeyAssignCtrl Class maps keyboard shortcuts, such as Alt+Shift+S, to a custom text format, such as "Alt + Shift + S". Each CMFCAcceleratorKey object maps a single shortcut key to a text format.
For more information about how to use shortcut keys and accelerator tables, see CKeyboardManager Class.
The following example demonstrates how to construct a CMFCAcceleratorKey object and how to use its Format method.
CString strKey; ACCEL accel; accel.fVirt = FVIRTKEY | FCONTROL; accel.key = VK_DOWN; CMFCAcceleratorKey helper(&accel); helper.Format(strKey);
Header: afxacceleratorkey.h
Constructs a CMFCAcceleratorKey object.
CMFCAcceleratorKey(); CMFCAcceleratorKey(LPACCEL lpAccel); ``` ### Parameters [in] `lpAccel` A pointer to a shortcut key. ### Remarks If you do not provide a shortcut key when you create a `CMFCAccleratorKey`, use the [CMFCAcceleratorKey::SetAccelerator](#cmfcacceleratorkey__setaccelerator) method to associate a shortcut key with your `CMFCAcceleratorKey` object. ## <a name="cmfcacceleratorkey__format"></a> CMFCAcceleratorKey::Format Translates the ACCEL structure to its associated string value.
void Format(CString& str) const;
### Parameters [out] `str` A reference to a `CString` object where the method writes the translated shortcut key. ### Remarks This method retrieves the string format of the associated shortcut key. You can set the string format of a [CMFCAcceleratorKey](../Topic/CMFCAcceleratorKey%20Class.md) object using either the constructor or the method [CMFCAcceleratorKey::SetAccelerator](#cmfcacceleratorkey__setaccelerator). ## <a name="cmfcacceleratorkey__setaccelerator"></a> CMFCAcceleratorKey::SetAccelerator Sets the shortcut key for the [CMFCAcceleratorKey](../Topic/CMFCAcceleratorKey%20Class.md) object.
void SetAccelerator(LPACCEL lpAccel);
### Parameters [in] `lpAccel` A pointer to a shortcut key. ### Remarks Use this method to set the shortcut key for a `CMFCAcceleratorKey` if you did not provide a shortcut key when you created the `CMFCAcceleratorKey`. ## See Also [Hierarchy Chart](../Topic/Hierarchy%20Chart.md) [Classes](../Topic/MFC%20Classes.md) [CKeyboardManager Class](../Topic/CKeyboardManager%20Class.md)