What is a keyboard accelerator key?
Accelerators are key combinations that produce WM_COMMAND messages (in some cases, wm_syscommand). In many cases, the program uses an accelerator key to repeat the action of a common menu item (however, the accelerator key can also be used to run non-menu functions). For example, many Windows programs have an Edit menu that contains a Delete or clear option, which is used to specify the DEL key as the accelerator key for that option. The user can select the Delete option from the menu by using the Alt key, or simply press the accelerator key Del. When a window message handler receives a WM_COMMAND message, it does not have to determine whether to use a menu or accelerator key.
Why do I use accelerator keys?
You may ask: Why should I use accelerator keys? Why can't I just intercept wm_keydown or WM_CHAR messages and implement the same menu function myself? And where is the benefit? You can certainly intercept keyboard messages for a single window application, but there are some benefits to using accelerators: You don't need to rewrite the menu and accelerator keys.
Accelerator keys are important for applications that have multiple windows and multiple window message handlers. As we can see, Windows sends keyboard messages to the window message handlers for the currently active window. For accelerator keys, however, Windows sends the WM_COMMAND message to the window message handler, which is given in the Windows function TranslateAccelerator by the name of the message handler. This is usually the main window and the window that owns the menu, which means that you don't need to rewrite the accelerator key's action handler for each window message handler.
This benefit becomes important if you are using a modeless modal dialog box (discussed in the next chapter) or a child window in the display area of the main window. If you define a specific accelerator key to move between different windows, you need only one window message handler to have this handler. The child window does not receive a WM_COMMAND message that is raised by the accelerator key.