Microsoft KB Archive/121623

{|
 * width="100%"|

HOWTO: Program Keyboard Interface for Owner-Draw Menus

 * }

Q121623

-

The information in this article applies to:


 * Microsoft Win32 Software Development Kit (SDK)
 * Microsoft Windows Software Development Kit (SDK) 3.1

-

SUMMARY
You 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 INFORMATION
Menus 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+. 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:


 * MF_POPUP if the cuurent menu is a popup menu.
 * MF_SYSMENU if the menu is the system menu.

The high-order word of lParam contains the menu handle of the current menu. The window with the owner-draw menus can process WM_MENUCHAR as follows:

  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 query words:

Keywords : kbMenu kbOSWinNT kbOSWin2000 kbSDKWin32 kbGrpDSUser kbOSWin

Issue type : kbhowto

Technology : kbWin32SDKSearch kbAudDeveloper kbWin3xSearch kbSDKSearch kbWin32sSearch kbWinSDKSearch kbWinSDK310