getmenuiteminfo
场景::GetMenuItemInfo,该如何解决
::GetMenuItemInfo
MENUITEMINFO info={0};
HMENU hmenu1 =::CreatePopupMenu();
char show[4]={0};
strcpy(show, "播放 ");
info.cbSize=sizeof(MENUITEMINFO);
info.fMask =MIIM_DATA | MIIM_ID | MIIM_TYPE;
info.fType =MF_STRING;
info.fState =0;
info.wID =1;
info.dwTypeData =show;
info.cch =4;
InsertMenuItem(hmenu1,1,TRUE,&info);
memset(&info,0,sizeof(info));
info.cbSize=sizeof(info);
info.cch=4;
info.fMask=MIIM_DATA | MIIM_ID | MIIM_TYPE;
info.fType= MFT_STRING;
::GetMenuItemInfo(hmenu1,1,TRUE,&info);
char *yuyu=(char *)info.dwTypeData;//空 这里为什么是空
//可以得到info.wID=1;
------解决方案--------------------
To retrieve a menu item of type MFT_STRING, first find the size of the string by setting the dwTypeData member of MENUITEMINFO to NULL and then calling GetMenuItemInfo. The value of cch+1 is the size needed. Then allocate a buffer of this size, place the pointer to the buffer in dwTypeData, increment cch, and call GetMenuItemInfo once again to fill the buffer with the string. If the retrieved menu item is of some other type, then GetMenuItemInfo sets the dwTypeData member to a value whose type is specified by the fType member
::GetMenuItemInfo
MENUITEMINFO info={0};
HMENU hmenu1 =::CreatePopupMenu();
char show[4]={0};
strcpy(show, "播放 ");
info.cbSize=sizeof(MENUITEMINFO);
info.fMask =MIIM_DATA | MIIM_ID | MIIM_TYPE;
info.fType =MF_STRING;
info.fState =0;
info.wID =1;
info.dwTypeData =show;
info.cch =4;
InsertMenuItem(hmenu1,1,TRUE,&info);
memset(&info,0,sizeof(info));
info.cbSize=sizeof(info);
info.cch=4;
info.fMask=MIIM_DATA | MIIM_ID | MIIM_TYPE;
info.fType= MFT_STRING;
::GetMenuItemInfo(hmenu1,1,TRUE,&info);
char *yuyu=(char *)info.dwTypeData;//空 这里为什么是空
//可以得到info.wID=1;
------解决方案--------------------
To retrieve a menu item of type MFT_STRING, first find the size of the string by setting the dwTypeData member of MENUITEMINFO to NULL and then calling GetMenuItemInfo. The value of cch+1 is the size needed. Then allocate a buffer of this size, place the pointer to the buffer in dwTypeData, increment cch, and call GetMenuItemInfo once again to fill the buffer with the string. If the retrieved menu item is of some other type, then GetMenuItemInfo sets the dwTypeData member to a value whose type is specified by the fType member