What is LoadAcceleratorA?
Posted: Sun Jun 11, 2023 7:02 am
So while reading the source from the decompile, I found this line . I decided to do some research and found that this is the function for loading Accelerator Tables in Windows found here https://learn.microsoft.com/en-us/windo ... eleratorsa. So what exactly is a Accelerator Table? Well according to the Windows API documentation found here https://learn.microsoft.com/en-us/windo ... tor-tables are a way of defining application shortcuts associated with your application this system is supposed to make easier to implement this functionality. For example:
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
Where IDR_ACCEL1 is our Accelerator Table and its id (these are completely arbitrary), and ID_TOGGLE_MODE, ID_DRAW_MODE, and ID_SELECT_MODE are commands that we wish to implement shortcuts for.
We would then define the Accelerator Table like the following
Here the first values on each row (0x4D, 0x70, and 0x71) represent the key codes for the shortcut. Next we put the Id of the command,
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.
The signature for this function is the following.
There is more documentation on the page to discuss how to use these Accelerators. I would recommend reading the page as I may have made some mistakes and the Windows documentation is pretty good.
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
);