在MFC功能区栏中删除以编程方式添加的面板分隔符

时间:2013-06-08 12:45:35

标签: c++ winapi mfc ribbon cmfcribbonpanel

我正在编写一个利用Ribbon栏的MFC应用程序,我在Ribbon编辑器中设计了大部分应用程序。但是,对于我的一个观点,我需要以编程方式添加一些按钮,我想在它们之间添加一个分隔符。

然而,当我然后切换视图时,我希望能够以编程方式删除按钮和分隔符,但我不知道如何去做,到目前为止,我有类似于以下内容(伪代码):< / p>

void AddButtons( CMFCRibbonBar& wndRibbonBar )
{
     // Get the relevant panel:
     CMFCRibbonCategory* pCategory = wndRibbonBar.GetCategory( 0 );
     CMFCRibbonPanel* pPanel = pCategory->GetPanel( 0 );

     // Insert the two buttons and add a separator:
     CMFCRibbonButton* pButton = new CMFCRibbonButton( ID_TESTBUTTON1, _T("Test1") );
     pPanel->Insert( pButton, 0 );
     pButton = new CMFCRibbonButton( ID_TESTBUTTON2, _T("Test2") );
     pPanel->Insert( pButton, 1 );

     pPanel->AddSeparator();
}

void RemoveButtons( CMFCRibbonBar& wndRibbonBar )
{
     // Get the relevant panel:
     CMFCRibbonCategory* pCategory = wndRibbonBar.GetCategory( 0 );
     CMFCRibbonPanel* pPanel = pCategory->GetPanel( 0 );

     // Remove the two buttons:
     pPanel->Remove( 1, TRUE );
     pPanel->Remove( 0, TRUE );

     // ToDo: Delete the separator:
}

我是否可以调用删除分隔符的函数,还是应该将其视为普通的Ribbon元素?

提前致谢!

1 个答案:

答案 0 :(得分:1)

将分隔符视为普通的Ribbon元素,它只是从CMFCRibbonSeparator类派生的另一个类(CMFCRibbonBaseElement):

 // Delete the separator:
 pPanel->Remove( 2, TRUE );

 // Remove the two buttons:
 pPanel->Remove( 1, TRUE );
 pPanel->Remove( 0, TRUE );