Defining an Accelerator Table

The following code example shows the syntax for accelerator table definitions.

acctablename ACCELERATORS [optional-statements] { event, idvalue, [type] [options] . . . } 

When using the ACCELERATORS statement in your resource-definition file, assign a unique name or resource identifier to the accelerator table. Windows CE uses the identifier to load the resource at run time.

Each accelerator you define requires a separate entry in the accelerator table. In each entry, you define the keystroke that generates the accelerator and the accelerator identifier. The keystroke is either an ASCII character code or a virtual-key code. Also specify if the keystroke must be used in some combination with the ALT, SHIFT, or CTRL key.

An ASCII keystroke is specified either by enclosing the ASCII character in double quotation marks or by using the integer value of the character in combination with the ASCII flag. The following code examples show how to define ASCII accelerators.

"A",   ID_ACCEL1         ; SHIFT+A 
65,    ID_ACCEL2, ASCII  ; SHIFT+A 
 

A keystroke that generates a virtual-key code is specified differently depending on whether the keystroke is an alphanumeric key or a non-alphanumeric key. For an alphanumeric key, the key's letter or number, enclosed in double quotation marks, is combined with the VIRTKEY flag. For a non-alphanumeric key, the Windows CE virtual-key code for the specific key is combined with the VIRTKEY flag. The following code examples show how to define virtual-key code accelerators.

"a",         ID_ACCEL3, VIRTKEY   ; A (caps-lock on) or an 
VK_INSERT,   ID_ACCEL4, VIRTKEY   ; INSERT key 
 

If you want the user to press the ALT, SHIFT, or CTRL key in some combination with the accelerator keystroke, specify the ALT, SHIFT, and CONTROL flags in the accelerator definition. The following code examples show possible combinations.

"B",   ID_ACCEL5, ALT                     ; ALT+SHIFT+B 
"I",   ID_ACCEL6, CONTROL, VIRTKEY        ; CTRL+I 
VK_F5, ID_ACCEL7, CONTROL, ALT, VIRTKEY   ; CTRL+ALT+F5 

You can also set the NOINVERT flag in the options parameter. NOINVERT prevents the selected menu item from being highlighted when its accelerator key is pressed. This is useful when defining accelerators for actions such as scrolling that do not correspond to a menu item.