Solved

Simple CMenu question

Posted on 1998-05-28
5
339 Views
Last Modified: 2013-11-20
Can anyone tell me why this code is not shading out the menu choice I want it to?

CMenu* TmpMenuPtr;
      
      if(_cAliasButton)
              _cAliasButton->EnableWindow(FALSE);
      TmpMenuPtr = GetMenu();
      if(TmpMenuPtr)
              TmpMenuPtr->EnableMenuItem(ID_ALIAS, MF_DISABLED | MF_GRAYED | MF_BYCOMMAND);
_cAliasButton is a button in the window, and I'm trying to gray the menu choice when I gray the button.
Thanks.
0
Comment
Question by:Beatachon
  • 3
  • 2
5 Comments
 
LVL 11

Accepted Solution

by:
mikeblas earned 50 total points
ID: 1315680
And this is in an MFC application?  If so, the reason the menu isn't going gray is that MFC uses OnUpdateCommandUI() notifications to decide the state of UI elements like menus. You should move your code to an OnUpdateCommandUI() handler for your menu item, and make your call against the pCmdUI object your handler is passed instead of calling GetMenu().

.B ekiM
0
 

Author Comment

by:Beatachon
ID: 1315681
Do I have to derive my own class from CControlBar, or can I catch this message in my window's message map?
0
 
LVL 11

Expert Comment

by:mikeblas
ID: 1315682
How does this involve CControlBar?

.B ekiM
0
 

Author Comment

by:Beatachon
ID: 1315683
I have since solved the problem, but in a simpler way. But in your method, where do I intercept that message? And which message am I looking for?
0
 
LVL 11

Expert Comment

by:mikeblas
ID: 1315684
Have a look at ClassWizard.  Select the class representing the window that holds your menu. Find the command ID for the menu item and select it in the left-hand list box, and look for the UPDATE_COMMAND_UI event in the right-hand list box. It'll add an OnUpdateCmdUI() handler to your class.

All MFC applicaitons are normally written this way, as it's almost always far more convenient than remembering to call EnableMenuItem() in all the right places everywhere command availability state changes.

.B ekiM

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

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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

830 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