简体   繁体   English

在MFC中删除菜单

[英]Removal of Menu in MFC

I have added menus like this in my program via resource editor 我通过资源编辑器在程序中添加了这样的菜单

Menu_A                          Menu_C


 Menu_B                           Menu_D

on the click of eventhandler of DI want to remove the Menu B under A 在DI的事件处理程序上单击,想要删除A下的菜单B

I have searched it found the following code but its not working for me. 我搜索了它,发现以下代码,但对我不起作用。

void     CmainWn   ::  OnCD()
{
    //IDR_MENU1 is resource file entry for Menu A

    CMenu topmenu;

    topmenu.LoadMenuA(IDR_MENU1); 

    CMenu& testsubmenu=*topmenu.GetSubMenu(1);

    //ID_A_B is resource file entry for menu B 

    testsubmenu.RemoveMenu(ID_A_B,MF_BYCOMMAND);

}

what is wrong with my code . 我的代码有什么问题。 what would be the correct one? 正确的是什么?

I am new to stackoverflow so sorry if code is not in proper format. 我是stackoverflow的新手,所以对不起,如果代码格式不正确。

The menu has already been created from IDR_MENU1 so that resource is no longer relevant. 该菜单已经从IDR_MENU1创建,因此资源不再相关。 Just start with a call to the main window's GetMenu to access the already created menu. 只需从调用主窗口的GetMenu开始即可访问已创建的菜单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM