Solved

Deleting top menu items

Posted on 1999-01-21
6
288 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
[X]
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
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
Suggested Courses

738 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