How to Program Keyboard Interface for Owner-Draw Menus

Last reviewed: September 29, 1995
Article ID: Q121623
The information in this article applies to:
  • Microsoft Windows Software Development Kit (SDK) versions 3.1
  • Microsoft Win32 Application Programming Interface (API) included with:

        - Microsoft Windows NT versions 3.5 and 3.51
        - Microsoft Windows 95 version 4.0
    

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+<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:

  • 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 reference words: 3.10 3.50 4.00
KBCategory: kbui
KBSubcategory: UsrMen


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 29, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.