動态菜單
打開String Table添加如下
IDS_BLUE 61446 蘭色
IDS_GREEN 61447 綠色
擴充菜單或者去除菜單
void Cvc1010View::OnExpand()
{
// TODO: 在此添加指令處理程式代碼
CMenu *pAddinMenu,*pTopMenu;
pTopMenu=AfxGetMainWnd()->GetMenu();
pAddinMenu=pTopMenu->GetSubMenu(5);//菜單次序從0開始
ASSERT(pAddinMenu!=NULL);
pAddinMenu->AppendMenuW(MF_SEPARATOR);//分隔線
CString MenuName;
for(int i=0;i<2;i++)
{
MenuName.LoadStringW(IDS_BLUE+i);//調用字元串
pAddinMenu->AppendMenuW(MF_STRING,IDS_BLUE+i,MenuName);
}
}
void Cvc1010View::OnStandard()
int i=pAddinMenu->GetMenuItemCount();//擷取菜單總數
if(5==i)
i--;
while(i>1)
{
pAddinMenu->RemoveMenu(i,MF_BYPOSITION);//删除菜單項
i--;
}
else
pAddinMenu->DeleteMenu(3,MF_BYPOSITION);//删除菜單項
pAddinMenu->RemoveMenu(2,MF_BYPOSITION);
本文轉自wenglabs部落格園部落格,原文連結:http://www.cnblogs.com/greatverve/archive/2011/03/09/vc100-17.html,如需轉載請自行聯系原作者