Hello everyone.
I am developing a new MFC
Multiple Top Level Document Application.
At the moment i am trying to figure a way to change the ribbon bar of a MainFrm
dynamically at two certain points of the application's lifecycle.
The first one is when the app has just opened and no document is opened yet. At this point i suppose that the application is in a initial state.
So, the first frame has a ribbon bar with some basic controls. When the user selects to create a new frame or open a saved document,
then instead of opening a new frame window, i "convert" the already opened window by loading another ribbon resource.
The code i achieve this is the following:
void CMyAppMainFrame::LoadRibbonFromUINT(UINT ribbon_res)
{
m_wndRibbonBar.RemoveAllCategories();
m_wndRibbonBar.RemoveAllFromTabs();
RemovePaneFromDockManager(&m_wndRibbonBar, TRUE, TRUE, FALSE, NULL);
VERIFY(m_wndRibbonBar.Create(this));
VERIFY(m_wndRibbonBar.LoadFromResource(ribbon_res));
m_wndRibbonBar.ForceRecalcLayout();
}
This step works fine.
The second case is when the user has only one document open and closes it.
In this case i want to keep the document open and just change the ribbon bar back to the basic one.
The user can close the document in two ways.
The first way works just fine!
But when i press the top right X button, although the control is also sent to CMyAppDoc::OnCloseDocument(), when the m_wndRibbonBar.ForceRecalcLayout() is called i get an exception.
I suppose that when i press the X button, perhaps the MFC frameworks invalidates some of FrameWnd members before the control reaches the CMyAppMainFrame::OnClose.
So when i try to recalc the RibbonBar layout, i get the exception.
Does anyone have a deeper understanding on the closing mechanism of MFC and how i could overcome this behaviour?
Thank you in advance!
What I have tried:
void CMyAppMainFrame::LoadRibbonFromUINT(UINT ribbon_res)
{
m_wndRibbonBar.RemoveAllCategories();
m_wndRibbonBar.RemoveAllFromTabs();
RemovePaneFromDockManager(&m_wndRibbonBar, TRUE, TRUE, FALSE, NULL);
VERIFY(m_wndRibbonBar.Create(this));
VERIFY(m_wndRibbonBar.LoadFromResource(ribbon_res));
m_wndRibbonBar.ForceRecalcLayout();
}