Simple (I hope) question

Posted on 2003-03-30
Medium Priority
Last Modified: 2013-11-20
I now know why I love working in C++ Builder.  I'm doing (customer requirements) a project where the PC side is in Visual C++ 6.0, and am pulling hairs.  I'm trying to do some simple things, and cannot begin to find where to do them.

The one I am trying now is to grey a menu line.  I design it grayed, and it shows up not grayed.  I use this code trying to change it's status...

     CMenu* pSysMenu = GetSystemMenu(FALSE);

and it remains not grayed.  I've tried several flag combination (MF_BYCOMMAND or MF_BYPOSITION), they fail, but other functions like AppendMenu are working, so the handle retrieved is correct.

I said this is easy, but it's pretty urgent, so I'm paying out a lot.
Question by:sburck
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
LVL 48

Accepted Solution

AlexFM earned 2000 total points
ID: 8233465
In SDI and MDI application you cannot set menu and toolbar items state directly. Instead of this you need to overwrite UPDATE_COMMAND_UI message handler. To do this, right-click on one of application classes (for exmple, CMainFrame), seleca "Add Windows Message Handler", select ID_BURN_FILEBURN and double-click on UPDATE_COMMAND_UI. In the function write:

LVL 48

Expert Comment

ID: 8233469
This handle is called when parent menu item is opened (WM_INITMENUPOPUP) or in idle time for toolbar buttons. Any changes done by using EnableMenuItem is overwritten by UPDATE_COMMAND_UI handler.

Author Comment

ID: 8233491
OK - that did it.  I'm going to ask why, though, there is a distinction, even though I'm hoping not to need it again for a long time.  The points are yours, but if you have a few seconds to explain why this is, I'd appreciate it.
LVL 48

Expert Comment

ID: 8233525
In SDI/MDI application program doesn't update menu and toolbar state directly. Instead of this you write condition which defines item state (enabled/disabled, checked/unchecked...). For example, if you want to have Save command enabled only when information is changed, you write:

void CMainFrame::OnUpdateFileSave(CCmdUI* pCmdUI)

instead of enabling menu item every tyme user types a symbol. Program changes it's state and MFC framework applies conditions when necessary.
Menu items are updated when parent menu is poped-up. Toolbar buttons are updated in idle time.
When some program event occures, you don't think "How to change all menu items according to the new state". You just keep the new state changing some flag.

Author Comment

ID: 8233534
Thanks for the explanation.

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

777 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