Owner-Drawn Menus and the WM_MENUCHAR Message

Menus other than owner-drawn menus can specify a menu mnemonic by inserting an underscore next to a character in the menu string. This allows the user to select the menu by typing alt and the menu mnemonic character. In owner-drawn menus, however, you cannot specify a menu mnemonic in this manner. Instead, your application must process the WM_MENUCHAR message to provide owner-drawn menus with menu mnemonics.

The WM_MENUCHAR message is sent when the user types a menu mnemonic that does not match any of the predefined mnemonics of the current menu. The value contained in wParam specifies the ASCII character that corresponds to the key the user pressed with the alt key. The low-order word of lParam specifies the type of the selected menu and can be on of the following values:

The high-order word of lParam contains the menu handle to the current menu. The window with the owner-drawn 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 to the current
               menu.
      return MAKELRESULT(nIndex, 2);
 

The two in the high-order word of the return value informs the system that the low-order word of the return value contains the zero-based index of the menu item to be selected.

The following constants (defined starting with Windows 95 and Windows NT version 4.0) correspond to the possible return values from the WM_MENUCHAR message:

Constant Value Meaning
MNC_IGNORE 0 The system should discard the character the user pressed and create a short beep on the system speaker.
MNC_CLOSE 1 The system should close the active menu.
MNC_EXECUTE 2 The system 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 The system should select the item specified in the low-order word of the return value.