Wednesday, March 25, 2009

Retrieve Menu Item Text with GetMenuItemInfo function


MENUITEMINFO MenuItem;
HMENU hmenu, hsubmenu;
HWND hwnd; //handle to main window
char szString[256];
int countLast =0;
//Initialize MENUITEMINFO structure:
memset(&MenuItem,0, sizeof(MenuItem));
MenuItem.cbSize = sizeof(MenuItem);
MenuItem.fMask =MIIM_TYPE;
MenuItem.fType = MFT_STRING;
//Important - the dwTypeData and cch data members must also be initialized to receive the string.
MenuItem.cch = 256;
MenuItem.dwTypeData = szString;
hmenu = GetMenu(hwnd); //get the menu
hsubmenu = GetSubMenu(hmenu,0); //get the first submenu

countLast = GetMenuItemCount(hsubmenu); //count number of items in the submenu; starts with 0;

GetMenuItemInfo(hsubmenu, 0, --countLast, &MenuItem );

MessageBox(NULL, MenuItem.dwTypeData, "Last Menu Item", MB_OK);

No comments:

Post a Comment