2
votes

I'd like to switch between different ribbons for different MDI child frames in my application. I know it's possible with the old style menus, but I can't get it working with the feature pack ribbons.

The code used when it's old style menus:

pDocTemplate = new CMultiDocTemplate(
    IDR_MAINFRAME,//Menu to load
    RUNTIME_CLASS(CModDoc),
    RUNTIME_CLASS(CModFrame), // custom MDI child frame
    RUNTIME_CLASS(CdotView));
if (!pDocTemplate)
    return FALSE;
AddDocTemplate(pDocTemplate);

pDocTemplate = new CMultiDocTemplate(
    IDR_RES_RNGACTIV,//Menu to load
    RUNTIME_CLASS(CModRangeDoc),
    RUNTIME_CLASS(CModRangeFrame), //custom MDI child frame
    RUNTIME_CLASS(CBlankView));
if (!pDocTemplate)
    return FALSE;
AddDocTemplate(pDocTemplate);

Another approach I'm thinking of is to unload the current Ribbon and load a new Ribbon from resources?

//Unload ribbon code?
m_wndRibbonBar.LoadFromResource(IDR_RIBBON);
2

2 Answers

1
votes

I ended up hiding the original ribbonbar and then loading and displaying a new one. Not sure if it's the best way to do it though.

    CMultiDocTemplate *pDoc = GetDocTemplate(7);
    if (pDoc)
    {
        CFloorActivDoc* pDocument = (CFloorActivDoc*)pDoc->CreateNewDocument();
        CFloorFrame* pFrame = (CFloorFrame*)pDoc->CreateNewFrame(pDocument, NULL);
        if (pFrame)
        {
            pDoc->InitialUpdateFrame(pFrame, pDocument);
            m_wndRibbonBar.ShowPane(FALSE, FALSE, TRUE);//Hide original ribbon
            m_FloorRibbonBar.Create(this);
            m_FloorRibbonBar.LoadFromResource(IDR_RIBBON_FLOORACT);
        }
1
votes

there is no need to have multiple CMFCRibbonBar objects if you don't need to, you can just use the CMFCRibbonBar::LoadFromResource and then you will have to use the CMFCRibbonBar::RecalcLayout method to apply the changes to the User Interface. Remember to check the return value of CMFCRibbonBar::LoadFromResource to be sure that the load was successful, and it is really important that you call the CMFCRibbonBar::RecalcLayout otherwise you will not see the new ribbon.