Why do I use accelerator keys? , what is the keyboard accelerator key

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.