如何用代码改变主框架上菜单的文本(Caption)。

解决方案 »

  1.   

    CWnd* pMain = AfxGetMainWnd();   //得到主框口
    if (pMain != NULL)
    {
        CMenu* mmenu = GetMenu();    //得到菜单
        
        pos = FindMenuItem(submenu, "&Save\tCtrl+S");    //找到要修改的菜单项
        if (pos > -1)
        {
           UINT id = submenu->GetMenuItemID(pos);
           submenu->ModifyMenu(id, MF_BYCOMMAND, id, "&Save Selection");   //修改
        }
    }
      

  2.   

    不好意思,上面这段代码有几处错误:FindMenuItem()是个自定义函数:
    int FindMenuItem(CMenu* Menu, LPCTSTR MenuString)
    {
       ASSERT(Menu);
       ASSERT(::IsMenu(Menu->GetSafeHmenu()));   int count = Menu->GetMenuItemCount();
       for (int i = 0; i < count; i++)
       {
          CString str;
          if (Menu->GetMenuString(i, str, MF_BYPOSITION) &&
             (strcmp(str, MenuString) == 0))
             return i;
       }   return -1;
    }CWnd* pMain = AfxGetMainWnd();   //得到主框口
    if (pMain != NULL)
    {
        CMenu* mmenu = pMain->GetMenu();    //得到菜单    CMenu *submenu;    pos = FindMenuItem(submenu, "&Save\tCtrl+S");    //找到要修改的菜单项
        if (pos > -1)
        {
           UINT id = submenu->GetMenuItemID(pos);
           submenu->ModifyMenu(id, MF_BYCOMMAND, id, "&Save Selection");   //修改
        }
    }