Solved

Simple CMenu question

Posted on 1998-05-28
5
330 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Windows Drag & Drop Location 2 85
Folder Comparison 12 52
withoutTen challenge 14 88
Not needed 13 57
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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 gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now