Solved

How to disable the sub menuitem of the main menu  in an SDI application?

Posted on 2002-05-06
7
670 Views
Last Modified: 2013-11-20
How to disable the sub menuitem of the main menu  in an SDI application? I tried with the following code its not working.

     CMenu* mmenu = GetMenu();
     CMenu* submenu = mmenu->GetSubMenu(0);
     submenu->EnableMenuItem(ID_VIEW_ITEM2, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);

Can anyone help me with some explanation.
Thanks in Advance.
0
Comment
Question by:bkkabi
[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
  • 2
  • 2
7 Comments
 
LVL 8

Accepted Solution

by:
VinExpert earned 25 total points
ID: 6991156
Hi,

Instead try the same code with MF_BYPOSITION. It should work. I had faced this problem and fixed it in that way.

Like :

CMenu* mmenu = AfxGetMainWnd()->GetMenu();
CMenu* submenu = mmenu->GetSubMenu(0);
submenu->EnableMenuItem(1, MF_BYPOSITION | MF_DISABLED);

Here, the sub menu item whoes position is 1 will be disabled.

Try it out.
VinExpert
0
 
LVL 3

Assisted Solution

by:Crius
Crius earned 25 total points
ID: 6991217
You have to make sure you are referencing the proper submenu. In your example:

    CMenu* mmenu = GetMenu();
    CMenu* submenu = mmenu->GetSubMenu(0);
    submenu->EnableMenuItem(ID_VIEW_ITEM2, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);

I noticed you are referring to GetSubMenu(0). In default MFC applications, this refers to the File menu. However, I noticed you are trying to disable the menu ID "ID_VIEW_ITEM2" which looks like a View menu item. The default View menu item is usually the 3rd or so menu item.

Try:

    CMenu* mmenu = GetMenu();
    CMenu* submenu = mmenu->GetSubMenu(2);
    submenu->EnableMenuItem(ID_VIEW_ITEM2, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);

Since we expect the View menu to be at GetSubMenu(2)...
0
 
LVL 4

Expert Comment

by:mblat
ID: 6991379
I think you may have to disable m_bAutoMenuEnable  member of CFrameWnd.  Otherwise enabling/disabling menu items handles  automatically

from MSDN:

CMainFrame::CMainFrame()
{
   // Set to FALSE so no ON_UPDATE_COMMAND_UI or
   // ON_COMMAND handlers are needed, and
   // CMenu::EnableMenuItem() will work as expected.
   m_bAutoMenuEnable  = FALSE;
}
0
 
LVL 3

Expert Comment

by:Crius
ID: 6991737
That could cause a few problems, but works better than manually doing it.

The best way to do it is to handle the On_Update messages sent for than menu item.

     ON_UPDATE_COMMAND_UI(ID_VIEW_ITEM2, OnUpdateViewItem2)


void CMyClass::OnUpdateViewItem2(CCmdUI* pCmdUI)
{
    //You can replace false with a variable to keep track of whether you want the menu enabled or not
    pCmdUI->Enable(false);
}
0
 
LVL 8

Expert Comment

by:VinExpert
ID: 7012049
Hi,

U got ur prob solved? If u have any questions, u may ask them here.

VinExpert
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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 tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

752 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