Solved

Deleting top menu items

Posted on 1999-01-21
6
286 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MFC Dialog 9 49
EvenOdd challenge 10 108
Not needed 13 112
x-bar in Google Sheets 2 53
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

770 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