Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2002-05-06
7
Medium Priority
?
683 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 100 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 100 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

722 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