Solved

Simple CMenu question

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
repeatEnd java challenge 42 84
CRON statement to run every 3 minutes except on Monday morning 12am to 2am 7 89
Window placement 17 74
scoreUp challenge 14 56
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…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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 is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

919 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

18 Experts available now in Live!

Get 1:1 Help Now