[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 296
  • Last Modified:

Deleting top menu items

Hi,
from program code I would like to delete a top menu item (having sub-menues). The sub-menues could be deletet in the ON_COMMAND_UI Function using
DeleteMenu(pCmdUI->m_nID, MF_BYCOMMAND);
But how to delete a top menu item (for example the "file" menue) in a standard MFC Program.
0
mangar
Asked:
mangar
  • 3
  • 3
1 Solution
 
migelCommented:
Hi!
Method to delete popup-submenu is same.
for example:
// method of  the frame wnd
{
CMenu* pMenu = GetMenu();
if (pMenu)
 pMenu->DeleteMenu(0, MF_BYPOSITION); // delete first item in the menu
}
Note: if your application is MDI. then framework changes main meny whenever child MDI  window is activated. So to delete popup sub menu of the child window permanently - you must modify window member m_hMenuShared.
fo example:
// CMDIchild derived class method
{
::DeleteMenu(m_hMenuShared, 0, MF_BYPOSITION);
}
0
 
mangarAuthor Commented:
Thanks, but your solution don´t work. GetMenu returns a valid Class != 0, but calling DeleteMenue causes an assertion on the IsMenu call of the MFC´s DeleteMenu Makro.

I have a standard MFC SDI Application with a "Debug" Menu. This "Debug" menu should be deletet in the release version of the application (depending on a compiler switch).

I tried to put your code in the "InitialUpdate" Handler of the CView derived class and in a ON_COMMAND_UI Handler of the document, but in both tries I got the same Error.  
0
 
migelCommented:
Hmm!
I think that you choise wrong place to delete this sub menu.
overriding LoadFrame in the CMainFrame class may be best  solution.
for example:
BOOL CMainFrame::LoadFrame(UINT nIDResource, DWORD dwDefaultStyle,
      CWnd* pParentWnd, CCreateContext* pContext)
{
BOOL bRes = CFrameWnd::LoadFrame(nIDResource, dwDefaultStyle,
      pParentWnd, pContext);
if (!bRes)
   return bRes;
::DeleteMenu(m_hMenuDefault, 0, MF_BYPOSITION);
::SetMenu(m_hWnd, m_hMenuDefault);
::DrawMenuBar(m_hWnd);
}

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
mangarAuthor Commented:
Thanks, but your solution don´t work. GetMenu returns a valid Class != 0, but calling DeleteMenue causes an assertion on the IsMenu call of the MFC´s DeleteMenu Makro.

I have a standard MFC SDI Application with a "Debug" Menu. This "Debug" menu should be deletet in the release version of the application (depending on a compiler switch).

I tried to put your code in the "InitialUpdate" Handler of the CView derived class and in a ON_COMMAND_UI Handler of the document, but in both tries I got the same Error.  
0
 
mangarAuthor Commented:
Thanks, your Solution works.
0
 
migelCommented:
Can i answer?
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now