当前位置: 代码迷 >> 综合 >> 孙鑫VC++深入详解:Lesson6 Part4 ---CMenu 类的应用:添加子菜单项AppendMenu,插入子菜单项InsertMenu,删除菜单DeleteMenu
  详细解决方案

孙鑫VC++深入详解:Lesson6 Part4 ---CMenu 类的应用:添加子菜单项AppendMenu,插入子菜单项InsertMenu,删除菜单DeleteMenu

热度:79   发布时间:2024-01-19 15:18:59.0

CMenu 类的应用 添加子菜单项AppendMenu,插入子菜单项InsertMenu,删除菜单DeleteMenu

//

CMenu::AppendMenu 

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


资源类对象都有一个成员变量来保存关联上的资源句柄
查看CMenu类,它有个成员变量m_hMenu:Specifies the handle to the Windows menu attached to the CMenu object. 


//------ 追加菜单,在已菜单后面追加一个子菜单 用函数CMenu::AppendMenu 
CMenu menu;
menu.CreatePopupMenu(); //初始化对象menu --- 创建一个空的弹出菜单
GetMenu()->AppendMenu(MF_POPUP,(UINT)menu.m_hMenu,"AppendMenu");
menu.Detach(); //把菜单资源与局部对象menu脱离,以免menu析构时,清除菜单.

//--

     

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{if (CFrameWnd::OnCreate(lpCreateStruct) == -1)return -1;if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||!m_wndToolBar.LoadToolBar(IDR_MAINFRAME)){TRACE0("Failed to create toolbar\n");return -1;      // fail to create}if (!m_wndStatusBar.Create(this) ||!m_wndStatusBar.SetIndicators(indicators,sizeof(indicators)/sizeof(UINT))){TRACE0("Failed to create status bar\n");return -1;      // fail to create}// TODO: Delete these three lines if you don't want the toolbar to//  be dockablem_wndToolBa
  相关解决方案