CMenu menu; menu.LoadMenu(IDR_MY_MENU); CString strMenuItem; menu.GetMenuString(0, strMenuItem, MF_BYPOSITION); // strMenuItem now contains the text of the first menu item
CMenu menu; menu.LoadMenu(IDR_MY_MENU); CString strMenuItem; menu.GetMenuString(ID_FILE_OPEN, strMenuItem, MF_BYCOMMAND); // strMenuItem now contains the text of the "Open" menu itemIn this example, we use the GetMenuString function to get the text of a specific menu item by its ID (in this case, ID_FILE_OPEN). We use the MF_BYCOMMAND flag to specify that we are using a menu item ID instead of a position index. Both of these examples use the CMenu class and its GetMenuString function to retrieve the text of a Windows menu item. The package library for this function is the Microsoft Foundation Class (MFC) library.