How to remove menu by ID?

I want to remove a menu IDR_MENU1 from the IDR_MAINFRAME.
Why my pmenu->RemoveMenu(IDR_MENU1, MF_BYCOMMAND) doesn't
work ?

IDR_MENU1 is a menu added to the IDR_MAINFRAME
via LoadMenu() command dynamically?

BOOL CMainFrame::MenuUnLoad(UINT MenuId)
{
      CMenu* pmenu = GetMenu();
//      pmenu->RemoveMenu(1, MF_BYPOSITION);  // This works
      pmenu->RemoveMenu(IDR_MENU1, MF_BYCOMMAND); // This doesn't
      DrawMenuBar();
      return TRUE;
}
nancytanAsked:
Who is Participating?
 
RONSLOWConnect With a Mentor Commented:
You main menu is a menu.  It has submenus.  These cannot be removed by command, because they don't have commands - they are just submenus.  You can only remove a menu item by command (eg ID_FILE_NEW)

0
 
nancytanAuthor Commented:
Edited text of question
0
 
nancytanAuthor Commented:
Edited text of question
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
nancytanAuthor Commented:
Edited text of question
0
 
nancytanAuthor Commented:
Edited text of question
0
 
nancytanAuthor Commented:
So, there is no way to remove submenu other then by using
 pmenu->RemoveMenu(1, MF_BYPOSITION)?
0
 
RONSLOWCommented:
That is so (to the best of my knowledge)

Of course, you should be able to loop thru your menu and find a submenu that contains an item with a known id, then remove that submenu.

Or you can rely on knowing the order (eg help menu always last, file menu always first etc).

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.