Pradyumn Singh
Pradyumn Singh

Reputation: 11

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 D I want to remove the Menu B under A

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.

Upvotes: 0

Views: 320

Answers (1)

ScottMcP-MVP
ScottMcP-MVP

Reputation: 10425

The menu has already been created from IDR_MENU1 so that resource is no longer relevant. Just start with a call to the main window's GetMenu to access the already created menu.

Upvotes: 1

Related Questions