Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 156
  • Last Modified:

Simple (I hope) question

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);
     pSysMenu->EnableMenuItem(ID_BURN_FILEBURN,MF_GRAYED | MF_DISABLED);

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.
0
sburck
Asked:
sburck
  • 3
  • 2
1 Solution
 
AlexFMCommented:
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:

pCmdUI->Enable(FALSE);
0
 
AlexFMCommented:
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.
0
 
sburckAuthor Commented:
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.
0
 
AlexFMCommented:
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)
{
    pCmdUI->Enable(m_bDirty);
}

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.
0
 
sburckAuthor Commented:
Thanks for the explanation.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now