Solved

Deleting top menu items

Posted on 1999-01-21
6
278 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

Author Comment

by:mangar
Comment Utility
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
Comment Utility
Thanks, your Solution works.
0
 
LVL 12

Accepted Solution

by:
migel earned 100 total points
Comment Utility
Can i answer?
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

772 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

11 Experts available now in Live!

Get 1:1 Help Now