LoadAccelerators
Synopsis
#include <windows.h>
HACCEL LoadAccelerators(
HINSTANCE hInstance,
LPCTSTR lpTableName
);
Parameters
Parameter | Type | Description |
---|---|---|
hInstance | HINSTANCE | Handle to the instance that contains the accelerator table resource. |
lpTableName | LPCTSTR | Name or integer identifier of the accelerator table resource. |
Return Value
If the function succeeds, the return value is a handle to the accelerator table. If the function fails, the return value is NULL
. To get extended error information, call GetLastError
.
Remarks
The accelerator table defines keyboard shortcuts for an application. To use an accelerator table, associate it with a window using TranslateAccelerator
inside the message loop. Accelerator resources are typically defined in a resource file (.rc) as follows:
IDD_MYACCEL ACCELERATORS
BEGIN
"^C", ID_FILE_COPY, VIRTKEY, CONTROL
"F1", ID_HELP_ABOUT, VIRTKEY
END
Example
#include <windows.h>
HINSTANCE g_hInst;
HACCEL g_hAccel;
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
g_hInst = hInstance;
g_hAccel = LoadAccelerators(g_hInst, MAKEINTRESOURCE(IDR_ACCEL));
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, g_hAccel, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return (int)msg.wParam;
}