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;

解决方案 »

  1.   

    memset(&info,0,sizeof(info));
    不是把所有变量都至0了么?
      

  2.   

    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
      

  3.   

    info.cbSize=sizeof(info);
    info.cch=0;
    info.fMask=MIIM_DATA | MIIM_ID | MIIM_TYPE;
    info.fType= MFT_STRING;
    ::GetMenuItemInfo(hmenu1,2,TRUE,&info);
    int yy=info.cch+1;//这个是正常的
    char *ss=new char[info.cch+1];
    ::GetMenuItemInfo(hmenu1,2,TRUE,&info);
    if(ss!=NULL&&strlen(ss)!=0){
    AfxMessageBox((char *)info.dwTypeData);//不对
    }