Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS Tech Support » How to disable/enable an entry in CExtMenuControlBar using the CommandManager Collapse All
Subject Author Date
Torsten Schucht Oct 24, 2007 - 3:53 AM

I want to disable or enable a command in the command manger. I do this by e.g.
...
CExtCmdItem* pCmdItem;
CString sProfile = g_CmdManager->ProfileNameFromWnd( this->GetSafeHwnd());
pCmdItem = g_CmdManager->CmdGetPtr(sProfile, ID_PROJECT_NEW);
pCmdItem->StateEnable(false);
...
Now I would like to have the entries in the menu bar which correspond to the commands to be enabled/disabled as well when the user opens the menu.

What I am doing right now is to ’walk’ through the menu items in CMainFrame::OnExtMenuPrepare, check the state of the command and enable/disable the coressponding popup item (see below).
....
INT nEntries = pPopup->ItemGetCount();
CExtCmdItem* pCmdItem;
CString sProfile = g_CmdManager->ProfileNameFromWnd( this->GetSafeHwnd());
for (INT i = 0; i < nEntries; i++)
{
    UINT nCmdID = pPopup->ItemGetCmdID(i);
    if (nCmdID != CExtPopupMenuWnd::TYPE_POPUP &&
                nCmdID != CExtPopupMenuWnd::TYPE_SEPARATOR)
    {
        pCmdItem = g_CmdManager->CmdGetPtr(sProfile,    nCmdID);
        ASSERT (pCmdItem != NULL);
        if (pCmdItem)
        {
            pPopup->ItemEnabledSet(i, pCmdItem->StateIsEnable());
        }
    }
}
...
This worked fine until I added the CExtThemeSwitcherToolControlBar to my CMainFrame. Now I get a NULL pointer for pCmdItem when I reach the first entry of the CExtThemeSwitcherToolControlBar menu. When it comes to the next entry the call to pPopup->ItemGetCmdID(i); fails with an illegal memory access exception.

At this point I think, that I do not understand the CommandManager correctly. Could you please clarify this and tell me how to make the enabling/disabling of commands and menu entries in the way it is meant to be done?

Thanks.
Torsten

Torsten Schucht Oct 26, 2007 - 2:36 PM

OK, I think I got it know. I thought that the Command Manger would do this for me as he does it with e.g. the icons of the commands.
Thanks for your help.

Torsten Schucht Oct 25, 2007 - 2:42 PM

Ok, thats the way I would do it for the theme switcher, but how is this done for the standard menu?

I thought that the command manager would handle the enable/disable state of the commands and also causes the display of the commands (in a menu or toolbar) to be accordingly enabled/disabled. Or is is the command manager just a container which maps id’s to icons, text, state, etc. ?

Suhai Gyorgy Oct 26, 2007 - 1:43 AM

I think you should do this as you’d do it in a pure MFC application: using ON_UPDATE_COMMAND_UI entries and associated state updating methods for your commands. This would set the proper state of a command no matter whether it is in a toolbar or menu.

Technical Support Oct 25, 2007 - 12:55 PM

You should use a CExtThemeSwitcherToolControlBar-derived class in which the following method is implemented:

CExtThemeSwitcherToolControlBar::ThemeSwitcher_OnButtonUpdate()

Torsten Schucht Oct 25, 2007 - 5:31 AM

Ok, thats the way I can access the commands from the CExtThemeSwitcherToolControlBar. But my primary question is: How can I get the enable state of a command synchronized to the state of the corresponding menu item?

Suhai Gyorgy Oct 24, 2007 - 6:05 AM

The global command manager can handle many command profiles. This is the reason why most CExtCmdManager methods have the parameter LPCTSTR sProfileName. The Theme switcher toolbar uses a profile of its own, the name of which is stored in its protected m_strCommandProfileName variable. Check out constructor of CExtThemeSwitcherToolControlBar.

Try to change your code like this, when accessing commands of CExtThemeSwitcherToolControlBar:
CString sProfile = g_CmdManager->ProfileNameFromWnd( m_wndToolBarUiLook->GetSafeHwnd() );