2

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);
Jak
  • 471
  • 5
  • 20

2 Answers2

1

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);
        }
Jak
  • 471
  • 5
  • 20
1

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.

Robson
  • 916
  • 5
  • 22
  • sadly the correct answer came too late, but the MFC tag is not much watched ahahahh – Robson Oct 29 '14 at 14:28
  • you are right, but there are some cases that you specifically want different ribbons because having just context categories is not enough. You can think about something like having different profiles, but there are also ribbon states that might be useful but i've never spent time on them. – Robson Nov 03 '14 at 10:57