void CMainFrame::OnAdd()
{
// TODO: Add your command handler code here
CMenu addMenu, *mainMenu;
if(!addMenu.LoadMenu(IDR_MENU1))
{
MessageBox("菜单装入失败!","错误",MB_OK | MB_ICONERROR);
return;
}
CString str = "颜色(&C)";
mainMenu = AfxGetMainWnd()->GetMenu();
mainMenu->InsertMenu(1, MF_POPUP | MF_BYPOSITION | MF_STRING,
(UINT)addMenu.GetSubMenu(0),str);
mainMenu->Detach();
addMenu.Detach();
DrawMenuBar();
}void CMainFrame::OnDelete()
{
// TODO: Add your command handler code here
CMenu *mainMenu;
CString str;
mainMenu = GetMenu();
for(int i=mainMenu->GetMenuItemCount()-1;i>=0;i--)
{
mainMenu->GetMenuString(i,str,MF_BYPOSITION);
if(str=="颜色(&C)")
mainMenu->DeleteMenu(i,MF_BYPOSITION);
break;
}
mainMenu->Detach();
DrawMenuBar();
}
解决方案 »
- 如何从一个命名管道句柄,得到它的名称?
- list control 问题,求大虾们解决
- static如何设置边框颜色,求助大家!谢谢
- CRichEditCtrl EM_GETLINE 返回 -1
- 请问图象边接收边显示,用两个线程可以吗?
- 关于connect函数的问题?
- 为什么安装完3721以后ie的网络实名可以马上生效呢?而我自己做的插件必须使ie重新启动一次才可以呢?
- 问个连我自己也知道弱的关于回车和换行的问题?
- 高分求助:在MFC 写的Activex组件想调用CView派生的一个类显示如何做到?
- 同一个软件在不同电脑上运行的差异
- 指针定义的问题
- 如何查找WORD的"首行"缩进 ,首行的位置?
改成
if(str.Compare(_T("颜色(&C)")) == 0)
{
// TODO: Add your command handler code here
CMenu addMenu, *mainMenu;
if(!addMenu.LoadMenu(IDR_MENU1))
{
MessageBox("菜单装入失败!","错误",MB_OK | MB_ICONERROR);
return;
}
CString str = "颜色(&C)";
mainMenu = AfxGetMainWnd()->GetMenu();
mainMenu->InsertMenu(1, MF_POPUP | MF_BYPOSITION | MF_STRING,
(UINT)addMenu.GetSubMenu(0),str);
//mainMenu->Detach();
addMenu.Detach();
DrawMenuBar();
}
改了这句以后,还是执行不到if语句里面的“mainMenu->DeleteMenu(i,MF_BYPOSITION);”
{
// TODO: Add your command handler code here
CMenu addMenu, *mainMenu;
if(!addMenu.LoadMenu(IDR_MENU1))
{
MessageBox("菜单装入失败!","错误",MB_OK | MB_ICONERROR);
return;
}
CString str = "颜色(&C)";
mainMenu = AfxGetMainWnd()->GetMenu();
mainMenu->InsertMenu(1, MF_POPUP | MF_BYPOSITION | MF_STRING,
(UINT)addMenu.GetSubMenu(0),str);
mainMenu->Detach();
addMenu.Detach();
DrawMenuBar();
}这句应该是 (UINT)((addMenu.GetSubMenu(0))->m_hMenu)