2

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?

ahmedsafan86
  • 1,776
  • 1
  • 26
  • 49

1 Answers1

1

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.

rrirower
  • 4,338
  • 4
  • 27
  • 45
  • How to save the state what is the state?? it saves it in the registry right now and load it but stay no seeing any updates. I just want it to see the updates the new changes, please if you have solved this problem make the answer more clear and provide us with some code or guidelines – ahmedsafan86 Feb 18 '14 at 13:18
  • 1
    The "state" is the current positioning and inclusion of all tool bars, menus, etc. currently defined to the application. You can think of it as a 'profile'. You can have many different 'states'. One can be defined to save a subset of the tool bars. Whenever a tool bar is added, updated, etc. we call the savestate method to save the 'state'. When the application is opened, the state is restored with the loadstate method. When it is closed, the state is saved again. It's really up to you to decide how and when you want to manage the state of the user interface objects in your application. – rrirower Feb 18 '14 at 14:02