HOWTO: Retrieve Handles to Menus and Submenus

ID: Q67688


The information in this article applies to:
  • Microsoft Win32 Software Development Kit (SDK), used with:
    • Microsoft Windows NT versions 3.5, 3.51
    • Microsoft Windows 95
  • Microsoft Windows Software Development Kit (SDK) versions 3.0, 3.1
  • Microsoft Windows 2000


SUMMARY

To change the contents of a menu, you must have its handle. The handle of the menu associated with a given window is available through the GetMenu() function.

To obtain a reference to a particular text item in the menu, use the GetMenuString() function. The definition for this function is:


   GetMenuString(hMenu, wIDItem, lpString, nMaxCount, wFlag) 
Where:

   hMenu     = The menu handle
   wIDItem   = The ID of the item or the zero-based offset of the
               item within the menu
   lpString  = The buffer that is to receive the text
   nMaxCount = The length of the buffer
   wFlag     = MF_BYCOMMAND or MF_BYPOSITION 
NOTE: Under Windows NT 4.0 or later, you can use the superseded function GetMenuItemInfo.

If a menu item has a mnemonic, the text will contain an ampersand (&) character preceding the mnemonic character.

To obtain the handle to a submenu of the menu bar, use the GetSubMenu() function. The second parameter, nPos, is the zero-based offset from the beginning of the menu.

Additional query words:

Keywords : kbMenu kbNTOS kbResource kbGrpUser kbWinOS
Version : WINDOWS:3.0,3.1,95
Platform : WINDOWS
Issue type : kbhowto


Last Reviewed: January 28, 2000
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.