sburck
asked on
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(I D_BURN_FIL EBURN,MF_G RAYED | 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.
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(I
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
ASKER
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.
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::OnUpdateFileSa ve(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.
void CMainFrame::OnUpdateFileSa
{
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.
ASKER
Thanks for the explanation.