Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2002-05-06
7
Medium Priority
?
688 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
  • 2
  • 2
7 Comments
 
LVL 8

Accepted Solution

by:
Vinayak Kumbar 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:Vinayak Kumbar
ID: 7012049
Hi,

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

VinExpert
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month12 days, 8 hours left to enroll

971 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