CMFCKeyMapDialog Class
The CMFCKeyMapDialog
class supports a control that maps commands to keys on the keyboard.
class CMFCKeyMapDialog : public CDialogEx
Name | Description |
---|---|
CMFCKeyMapDialog::CMFCKeyMapDialog | Constructs a CMFCKeyMapDialog object. |
Name | Description |
---|---|
CMFCKeyMapDialog::DoModal | Displays a keyboard mapping dialog box. |
Name | Description |
---|---|
CMFCKeyMapDialog::FormatItem | Called by the framework to build a string that describes a key mapping. By default, the string contains the command name, the shortcut keys used, and the shortcut key description. |
CMFCKeyMapDialog::GetCommandKeys | Retrieves a string that contains a list of shortcut keys associated with the specified command. |
CMFCKeyMapDialog::OnInsertItem | Called by the framework before a new item is inserted into the internal list control that supports the keyboard mapping control. |
CMFCKeyMapDialog::OnPrintHeader | Called by the framework to print the header for the keyboard map on a new page. |
CMFCKeyMapDialog::OnPrintItem | Called by the framework to print a keyboard mapping item. |
CMFCKeyMapDialog::OnSetColumns | Called by the framework to set captions for the columns in the internal list control that supports the keyboard mapping control. |
CMFCKeyMapDialog::PrintKeyMap | Called by the framework when a user clicks the Print button. |
CMFCKeyMapDialog::SetColumnsWidth | Called by the framework to set the width of the columns in the internal list control that supports the keyboard mapping control. |
Use the CMFCKeyMapDialog
class to implement a resizable keyboard mapping dialog box. The dialog box uses a list view control to display keyboard shortcuts and their associated commands.
To use the CMFCKeyMapDialog
class in an application, pass in a pointer to the main frame window as a parameter to the CMFCKeyMapDialog
constructor. Then call the DoModal
method to start a modal dialog box.
Header: afxkeymapdialog.h
Constructs a CMFCKeyMapDialog
object.
CMFCKeyMapDialog(
CFrameWnd* pWndParentFrame,
BOOL bEnablePrint=FALSE);
pWndParentFrame
[in] A pointer to the parent window of the CMFCKeyMapDialog
object.
bEnablePrint
[in] TRUE if the list of accelerator keys can be printed; otherwise, FALSE. The default is FALSE.
The following example demonstrates how to construct an object of the CMFCKeyMapDialog
class. This example is part of the Visual Studio Demo sample.
// this points to a CMainFrame class which extends the
// CMDIFrameWndEx class
CMFCKeyMapDialog dlg(this, TRUE /* Enable Print */);
Displays a keyboard mapping dialog box.
virtual INT_PTR DoModal();
A signed integer, such as IDOK or IDCANCEL, that is passed to the CDialog::EndDialog method. The method, in turn, closes the dialog box. For more information, see CDialog::DoModal.
The keyboard mapping dialog box enables you to select and assign accelerator keys to various categories of commands. In addition, you can copy the selected accelerator keys and their description to the clipboard.
Called by the framework to build a string that describes a key mapping. By default, the string contains the command name, the shortcut keys used, and the shortcut key description.
virtual CString FormatItem(int nItem) const;
nItem
[in] The zero-based index of an item in the internal list of key mappings.
A CString
object that contains the formatted item text.
Retrieves a string value. The string contains a list of shortcut keys that are associated with a specified command.
virtual CString GetCommandKeys(UINT uiCmdID) const;
uiCmdID
[in] A command ID.
A semicolon-delimited (';') list of shortcut keys that is associated with the specified command.
Called by the framework before a new item is inserted into an internal list control that supports the keyboard mapping control.
virtual void OnInsertItem(
CMFCToolBarButton* pButton,
int nItem);
pButton
[in] A pointer to a toolbar button that is used to map a keyboard key combination to a command name and description. The key map item is stored in an internal list control.
nItem
[in] A zero-based index that specifies where to insert the new key map item in the internal list control.
Called by the framework to print the header for the keyboard map on a new page.
virtual int OnPrintHeader(
CDC& dc,
int nPage,
int cx) const;
dc
[in] The device context for the printer.
nPage
[in] The page number to print.
cx
[in] The horizontal offset of the header, in pixels.
If successful, the height of the printed text. For more information, see the Return Value section of CDC::DrawText.
The framework uses this method to print the keyboard map. By default, this method prints the page number, application name, and dialog box title.
Called by the framework to print a keyboard mapping item.
virtual int OnPrintItem(
CDC& dc,
int nItem,
int y,
int cx,
BOOL bCalcHeight) const;
dc
[in] The device context of the printer.
nItem
[in] The zero-based index of the item to print.
y
[in] The vertical offset between the top of the page and the position of the item.
cx
[in] The horizontal offset between the left of the page and the position of the item.
bCalcHeight
[in] TRUE to calculate the best height for the print item; FALSE to truncate the print item so that it fits the default space.
The height of the printed item.
The framework calls this method to print a key map dialog box item. By default, this method prints the item's command name, shortcut keys, and command description.
Called by the framework to set captions for the columns in the internal list control that supports the keyboard mapping control.
virtual void OnSetColumns();
By default, this method obtains the captions for the columns from three resources. The command column caption is from IDS_AFXBARRES_COMMAND, the key column caption is from IDS_AFXBARRES_KEYS, and the description column caption is from IDS_AFXBARRES_DESCRIPTION.
Called by the framework when a user clicks the Print button.
virtual void PrintKeyMap();
The PrintKeyMap
method prints the key map. It initiates a new print job and then repeatedly calls the CMFCKeyMapDialog::OnPrintHeader and CMFCKeyMapDialog::OnPrintItem methods until all the key mappings are printed.
Called by the framework to set the width of the columns in the internal list control that supports the keyboard mapping control.
virtual void SetColumnsWidth();
This method sets the internal list control's columns to default widths. First, the width of the shortcut keys column is calculated. Then one-third of the remaining width is allocated to the command column and the remaining two-thirds is allocated to the description column.