?
Solved

Grey out the menu in MFC

Posted on 2005-05-16
4
Medium Priority
?
488 Views
Last Modified: 2013-11-20
I am trying to grey out the submenu item if a flag is set to false.

how do i acheive this ? Can anyone send a snippet please



ON_COMMAND(ID_TOOLS_DELETECURVES, OnToolsDelete)

void XgView::OnToolsDelete()
{
  XgDeleteDlg Cdlg(AGROUP);

      if (Cdlg.DoModal() == IDOK) {}
}
0
Comment
Question by:hari4130
  • 3
4 Comments
 
LVL 30

Accepted Solution

by:
Axter earned 1200 total points
ID: 14011910
You can disable a menu item via following method:

CMenu* pMenu = GetMenu();
 pMenu->EnableMenuItem(ID_FILE_NEW,MF_GRAYED);

However, I recommend you use the ON_UPDATE_COMMAND_UI MFC macro to do this
0
 
LVL 30

Expert Comment

by:Axter
ID: 14011930
To use the ON_UPDATE_COMMAND_UI MFC macro, select the view in ClassWizard, select the menu item (ID_FILE_NEW or whatever), and create a handle for ON_UPDATE_COMMAND_UI.
0
 
LVL 30

Expert Comment

by:Axter
ID: 14011970
Here's example code for your ON_UPDATE_COMMAND_UI function:

void CMainFrame::OnUpdateCommand...(CCmdUI* pCmdUI)
{
     pCmdUI->Enable(bEnableThisMenuItem );    
}

In above example function, bEnableThisMenuItem is a member BOOL variable you create to enable or disable your menu item.
0
 
LVL 3

Expert Comment

by:NawalKishore1976
ID: 14017544
Hi either use the OnUpdate or Modify Menu

void CMainFrame::OnUpdateFileTest(CCmdUI* pCmdUI)
{
      pCmdUI->Enable(FALSE);

      //ModifyMenu(hMenu, SC_CLOSE, MF_BYCOMMAND|MF_GRAYED, SC_CLOSE, "Close")
      
}
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses

840 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