CMFCToolBar & CMFCMenuBar don't show dynamic items by default

1k Views Asked by At

I created a MFC application that uses CMFCToolBar and CMFCMenuBar. It saves it's first time items state, when I change or add any dynamic items I still see the first state the deleted items stay there the added items are not shown, then I found that all items are serialized in the registry and loaded each time, all of our applications load dynamic menu items or toolbar buttons from the modules of the application, really I couldn't make it work except with the following solution

class CToolBarEx : public CMFCToolBar
{
public:
    CToolBarEx()
    {
    }

    virtual BOOL LoadState(LPCTSTR /*lpszProfileName*/ = NULL, int /*nIndex*/ = -1, UINT /*uiID*/ = (UINT) -1)  {   return FALSE;   }
    virtual BOOL SaveState(LPCTSTR /*lpszProfileName*/ = NULL, int /*nIndex*/ = -1, UINT /*uiID*/ = (UINT) -1)  {   return FALSE;   }


};
class CMenuBarEx : public CMFCMenuBar
{
public:
    CToolBarEx()
    {
    }

    virtual BOOL LoadState(LPCTSTR /*lpszProfileName*/ = NULL, int /*nIndex*/ = -1, UINT /*uiID*/ = (UINT) -1)  {   return FALSE;   }
    virtual BOOL SaveState(LPCTSTR /*lpszProfileName*/ = NULL, int /*nIndex*/ = -1, UINT /*uiID*/ = (UINT) -1)  {   return FALSE;   }


};

that was the only way that I could use to add dynamic items to toolbars or menubars but this is not a solution, I don't take any advantage of the customization tools and saving the menubars positions, Is this how microsoft wants the people to deal with menus and toolbars? to push it one time and no changes are allowed? or I'm missing something about this?

1

There are 1 best solutions below

2
On

Unfortunately, that's the way it works since Microsoft derives its CMFC classes from the BCG toolkit. We had the same issue in our application and solved it by updating the work space (eg. tool bars, menu items, etc.) from the mainframe class. Additionally, we elected to save the state in an XML file instead.