help,关于改变菜单状态的问题,来看一下

laserman 2002-05-13 02:11:19
一个程序,需要改变菜单的状态
1。顶层菜单有两种,pop-up和非pop-up的,pop-up的没有ID,非pop-up的有ID。
2。按下一个按钮时,要求所有的顶层菜单为灰色,不可用。我是用EnableMenuItem函数做的,但没有ID的菜单项不知如何解决。
3。按下另外一个按钮,要求菜单变回原来状态。
4。如何更新顶层菜单项?我在编程时无法更新菜单项,只有当鼠标移动到菜单上时,菜单状态才会更新。
那位大侠帮帮忙,谢谢
...全文
33 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
laserman 2002-05-13
  • 打赏
  • 举报
回复
搞定了,带pop-up属性的不能用ModifyMenu(...),会被删除
菜单更新用DrawMenuBar()
freelybird 2002-05-13
  • 打赏
  • 举报
回复
CMenu::ModifyMenu(...)
freelybird 2002-05-13
  • 打赏
  • 举报
回复
CMenu::ModifyMenu(...)
freelybird 2002-05-13
  • 打赏
  • 举报
回复
CMenu::ModifyMenu(...)
wealth 2002-05-13
  • 打赏
  • 举报
回复
MSDN中的First CD中Sample的VC的MFC中就有,自己找一下就行了,如果嫌一个一个找麻烦的话,全部拷过来再逐个运行就可以找到答案啦。
freelybird 2002-05-13
  • 打赏
  • 举报
回复
void CMainFrame::OnChangeFileMenu()
{
// Get the menu from the application window.
CMenu* mmenu = GetMenu();

// Look for "File" menu.
int pos = FindMenuItem(mmenu, "&File");
if (pos == -1)
return;

// Remove "New" menu item from the File menu.
CMenu* submenu = mmenu->GetSubMenu(pos);
pos = FindMenuItem(submenu, "&New\tCtrl+N");
if (pos > -1)
submenu->RemoveMenu(pos, MF_BYPOSITION);

// Look for "Open" menu item from the File menu. Insert a new
// menu item called "Close" right after the "Open" menu item.
// ID_CLOSEFILE is the command id for the "Close" menu item.
pos = FindMenuItem(submenu, "&Open...\tCtrl+O");
if (pos > -1)
submenu->InsertMenu(pos + 1, MF_BYPOSITION, ID_CLOSEFILE, "&Close");

// Rename menu item "Save" to "Save Selection".
pos = FindMenuItem(submenu, "&Save\tCtrl+S");
if (pos > -1)
{
UINT id = submenu->GetMenuItemID(pos);
submenu->ModifyMenu(id, MF_BYCOMMAND, id, "&Save Selection");
}

// Associate a context help ID with File menu, if one is not found.
// ID_FILE_CONTEXT_HELPID is the context help ID for the File menu
// that is defined in resource file.
if (submenu->GetMenuContextHelpId() == 0)
submenu->SetMenuContextHelpId(ID_FILE_CONTEXT_HELPID);

// Set "Open" menu item as the default menu item for the File menu,
// if one is not found. So, when a user double-clicks the File
// menu, the system sends a command message to the menu's owner
// window and closes the menu as if the File\Open command item had
// been chosen.
if (submenu->GetDefaultItem(GMDI_GOINTOPOPUPS, TRUE) == -1)
{
pos = FindMenuItem(submenu, "&Open...\tCtrl+O");
submenu->SetDefaultItem(pos, TRUE);
}
}

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧