How to Program Keyboard Interface for Owner-Draw MenusLast reviewed: September 29, 1995Article ID: Q121623 |
The information in this article applies to:
SUMMARYYou can implement the keyboard interface for owner-draw menus, which allow a user to access a menu by typing a menu mnemonic, by processing the WM_MENUCHAR message.
MORE INFORMATIONMenus other than owner-draw menus can specify a menu mnemonic by inserting an underscore next to a character in the menu string so that the user can select the menu by typing ALT+<menu mnemonic character>. But in owner-draw menus, you cannot specify a menu mnemonic in this manner. Instead, you must process the WM_MENUCHAR message to provide owner-draw menus with menu mnemnoics. WM_MENUCHAR is sent when the user types a menu mnemonic that does not match any of the predefined mnemonics of the current menu. wParam specifies the ASCII character that corresponds to the key the user pressed together with the ALT key. The low-order word of lParam specifies the type of the selected menu and contains:
case WM_MENUCHAR: nIndex = Determine index of menu item to be selected from character that was typed and handle of the current menu. return MAKELRESULT(nIndex, 2);The 2 in the high-order word of the return value informs Windows that the low-order word of the return value contains the zero-based index of the menu item to be selected by Windows. Windows 95 defines four new constants that correspond to the possible return values from the WM_MENUCHAR message:
Constant Value Meaning
MNC_IGNORE 0 Informs Windows that it should discard the character the user pressed and create a short beep on the system speaker. MNC_CLOSE 1 Informs Windows that it should close the active menu. MNC_EXECUTE 2 Informs Windows that it should choose the item specified in the low-order word of the return value. The owner window receives a WM_COMMAND message. MNC_SELECT 3 Informs Windows that it should select the item specified in the low-order word of the return value. |
Additional reference words: 3.10 3.50 4.00
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |