CMenu::RemoveMenu  is failing

Posted on 2003-02-27
Medium Priority
Last Modified: 2013-11-20

I am using RemoveMenu() to remove ALL menu items in my sub menus, however it does not delete ALL the items. It fails to remove a couple of items.
I cannot figure out why it is not deleting all the items
I have tried using GetLastError() however this only returns 0.

Any help would be much appreciated !

void myModule::RemoveSubMenuItems( CMenu* &pSubMenu)
  // Remove All menu items from the sub menu.
   int count = pSubMenu->GetMenuItemCount();

   for (int i = 0; i < count; i++)
    if (!pSubMenu->RemoveMenu(i, MF_BYPOSITION))
  CHAR szBuf[80];
  DWORD dw = GetLastError();
  sprintf(szBuf, "FAILED to RemoveMenu item: GetLastError returned %u\n", dw);

Question by:Danny01
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 48

Accepted Solution

AlexFM earned 300 total points
ID: 8033000
for (int i = count - 1; i >=0; i--)
    pSubMenu->RemoveMenu(i, MF_BYPOSITION);

When you remove menu items from the start, numbers of all other items are changed.


Author Comment

ID: 8033706
Thank you , this worked ... You have saved me lots of time and frustration !!

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question