Solved

Deleting top menu items

Posted on 1999-01-21
6
281 Views
Last Modified: 2013-11-20
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
Comment
Question by:mangar
  • 3
  • 3
6 Comments
 
LVL 12

Expert Comment

by:migel
ID: 1328122
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
 

Author Comment

by:mangar
ID: 1328123
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
 
LVL 12

Expert Comment

by:migel
ID: 1328124
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:mangar
ID: 1328125
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
 

Author Comment

by:mangar
ID: 1328126
Thanks, your Solution works.
0
 
LVL 12

Accepted Solution

by:
migel earned 100 total points
ID: 1328127
Can i answer?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
A short film showing how OnPage and Connectwise integration works.

914 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now