Code: Select all
// Load accelerator (don't know what this does) LoadAcceleratorsA(hInstance, "AppAccel");
Imagine we had the following shortcuts associated with the following commands:
Shortcut Command
CTRL+M Toggle between modes.
F1 Switch to draw mode.
F2 Switch to selection mode.
We would write the following code to define a Accelerator Table like this
Code: Select all
#define IDR_ACCEL1 101
#define ID_TOGGLE_MODE 40002
#define ID_DRAW_MODE 40003
#define ID_SELECT_MODE 40004
We would then define the Accelerator Table like the following
Code: Select all
#include "resource.h"
IDR_ACCEL1 ACCELERATORS
{
0x4D, ID_TOGGLE_MODE, VIRTKEY, CONTROL // ctrl-M
0x70, ID_DRAW_MODE, VIRTKEY // F1
0x71, ID_SELECT_MODE, VIRTKEY // F2
}
and then we add VIRTUALKEY ("The keyword VIRTKEY means the first entry is a virtual-key code. The other option is to use ASCII characters.")
and finally we can add modifiers for our shortcut.
Finally we can load this accelerator like the following.
Code: Select all
HACCEL hAccel = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDR_ACCEL1));
Code: Select all
HACCEL LoadAcceleratorsA(
[in, optional] HINSTANCE hInstance,
[in] LPCSTR lpTableName
);