在MDI应用程序中的不同功能区之间切换

Switching between different ribbons in an MDI application

本文关键字:功能区 之间 MDI 应用程序      更新时间:2023-10-16

我想在应用程序中的不同MDI子框架的不同功能区之间切换。我知道用老式菜单是可能的,但我不能用功能包功能带。

当它是老式菜单时使用的代码:

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);

我正在考虑的另一种方法是卸载当前功能区并从资源中加载新功能区?

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

如果不需要多个CMFCRibbonBar对象,只需使用CMFCRibonBar::LoadFromResource,然后必须使用CMFCRibbonBar::RecalcLayout方法将更改应用于用户界面。请记住检查CMFCRibbonBar::LoadFromResource的返回值以确保加载成功,并且调用CMFCRibonBar::RecalcLayout非常重要,否则将看不到新功能区。

我最终隐藏了原来的ribbonbar,然后加载并显示了一个新的ribbonpar。但不确定这是否是最好的方法。

    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);
        }