?
Solved

Simple CMenu question

Posted on 1998-05-28
5
Medium Priority
?
352 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 11

Accepted Solution

by:
mikeblas earned 200 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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 is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

762 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