HOWTO: Retrieve Handles to Menus and Submenus

ID: Q67688


The information in this article applies to:


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.


Keywords          : kbMenu kbNTOS kbResource kbGrpUser kbWinOS 
Version           : 
Platform          : 
Issue type        : kbhowto 

Last Reviewed: March 6, 1999