做了一个MFC单文档的程序,我想获得菜单的文本信息,比如菜单编辑里有个子菜单为"开始",我要获得它,并且把它修改为"暂停",该怎么做啊.

解决方案 »

  1.   

    // CMainFrame::OnChangeFileMenu() is a menu command handler for 
    // CMainFrame class, which in turn is a CFrameWnd-derived class. 
    // It modifies the File menu by inserting, removing and renaming 
    // some menu items. Other operations include associating a context 
    // help id and setting default menu item to the File menu. 
    // CMainFrame is a CFrameWnd-derived class.
    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);
       }
    }// FindMenuItem() will find a menu item string from the specified
    // popup menu and returns its position (0-based) in the specified 
    // popup menu. It returns -1 if no such menu item string is found.
    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;
    }
      

  2.   

    用CMenu::ModifyMenu BOOL ModifyMenu(
       UINT nPosition,
       UINT nFlags,
       UINT_PTR nIDNewItem = 0,
       LPCTSTR lpszNewItem = NULL 
    );
    BOOL ModifyMenu(
       UINT nPosition,
       UINT nFlags,
       UINT_PTR nIDNewItem,
       const CBitmap* pBmp 
    );
      

  3.   

    GetMenu
    然后
    ModifyMenu 即可
      

  4.   

    http://msdn2.microsoft.com/zh-CN/library/89c2aa4b.aspx
      

  5.   

    CMenu * pMenu = GetMenu();
    CString str;
    pMenu->GetMenuString(ID_FILE_TEST, str, MF_BYCOMMAND);
    if ( str == "开始")
    {
        pMenu->ModifyMenu(ID_FILE_TEST, MF_BYCOMMAND, ID_FILE_TEST, "停止");}
      

  6.   

    看域名还以为是中文的msdn完工了呢~