龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 软件开发 > VC开发 >

在VC中动态改变菜单[图](2)

时间:2009-12-30 15:42来源:未知 作者:admin 点击:
分享到:
第五步: 找到添加的六个按钮的处理函数,依次添加如下的代码: void CChangeMenu::OnClear() { AfxGetMainWnd()-SetMenu(NULL); AfxGetMainWnd()-DrawMenuBar(); } void CChangeMenu:

  第五步:

  找到添加的六个按钮的处理函数,依次添加如下的代码:

  void CChangeMenu::OnClear()
   {
    AfxGetMainWnd()->SetMenu(NULL);
    AfxGetMainWnd()->DrawMenuBar();
   }

  void CChangeMenu::OnGoone()
   {
    if(!menu1){
     menu1.LoadMenu(IDR_MENU1);
     AfxGetMainWnd()->SetMenu(&menu1);
     AfxGetMainWnd()->DrawMenuBar();
     menu1.Detach();
    }
   }

  void CChangeMenu::OnGotwo()
   {
    if(!menu2){
     menu2.LoadMenu(IDR_MAINFRAME);
     AfxGetMainWnd()->SetMenu(&menu2);
     AfxGetMainWnd()->DrawMenuBar();
     menu2.Detach();
    }
   }

  void CChangeMenu::OnAdd()
   {
    static int x=400;
    AfxGetMainWnd()->GetMenu()->AppendMenu(MF_STRING,x,"mynew");
    AfxGetMainWnd()->DrawMenuBar();
    x++;
   }

  void CChangeMenu::OnAdditem()
   {
    static int y=500;
    AfxGetMainWnd()->GetMenu()->GetSubMenu(0)->InsertMenu(1,MF_BYPOSITION,y,"mynewitem");
    AfxGetMainWnd()->DrawMenuBar();
    y++;
   }

  void CChangeMenu::OnEdit()
   {
    AfxGetMainWnd()->GetMenu()->ModifyMenu(0,MF_BYPOSITION,402,"dfd");
    AfxGetMainWnd()->DrawMenuBar();
   }

  好了,到这里我们所有的功能就都实现了,快编译运行一下吧!怎么样?还满意吗?

精彩图集

赞助商链接