我的程序的菜单栏初始状态如下:
---------------------------------
文件    编辑      查看        帮助
 -打开   -复制    -工具栏
 -保存   -剪切    -状态栏
---------------------------------
如果我要加一个菜单如下:
文件    编辑      查看        帮助   测试
 -打开   -复制    -工具栏 -测试1
 -保存   -剪切    -状态栏 -测试2
----------------------------------
并且将测试1、测试2两个菜单项与程序中已经存在的两个程序块关联起来,
我应该如何做?
我尝试做的时候,出现错误,我的代码如下:
CMenu *pmenu,*psubmenu;
pmenu=GetMenu();
pmenu->InsertMenu(-1,MF_BYPOSITION,0,"测试");
psubmenu=pmenu->GetSubMenu(0);
ASSERT(psubmenu!=NULL);//在此处出现错误请大师帮助,非常感谢!!!

解决方案 »

  1.   

    CMenu::InsertMenu :
    Inserts a new menu item at the position specified by nPosition and moves other items down the menu.意思就是InsertMenu是用于插入菜单里的项(Item)的,不是添加一个弹出菜单的。
      

  2.   

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

  3.   

    例程:
    // The code fragment below shows how to create a new menu for the
    // application window using CreateMenu() and CreatePopupMenu().
    // Then, the created menu will replace the current menu of the
    // application. The old menu will be destroyed with DestroyMenu().
    // NOTE: The code fragment below is done in a CFrameWnd-derived class.// Create a new menu for the application window.
    VERIFY(m_NewMenu.CreateMenu());// Create a "File" popup menu and insert this popup menu to the
    // new menu of the application window. The "File" menu has only
    // one menu item, i.e. "Exit".
    VERIFY(m_FileMenu.CreatePopupMenu());
    m_FileMenu.AppendMenu(MF_STRING, ID_APP_EXIT, (LPCTSTR)"E&xit");
    m_NewMenu.AppendMenu(MF_POPUP, (UINT) m_FileMenu.m_hMenu, "&File");// Remove and destroy old menu
    SetMenu(NULL);
    CMenu* old_menu = CMenu::FromHandle(m_hMenuDefault);
    old_menu->DestroyMenu();// Add new menu.
    SetMenu(&m_NewMenu);// Assign default menu
    m_hMenuDefault = m_NewMenu.m_hMenu;