Link to home
Start Free TrialLog in
Avatar of Danny01
Danny01

asked on

CMenu::RemoveMenu is failing

Hi,

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 !
Thanks,
Danny


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);
 
  AfxMessageBox(szBuf);
    }

   }
}
ASKER CERTIFIED SOLUTION
Avatar of AlexFM
AlexFM

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Danny01
Danny01

ASKER

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