删除一个编程添加的面板分隔符在MFC Ribbon Bar

Removing a programmatically added panel separator in MFC Ribbon Bar

本文关键字:分隔符 MFC Bar Ribbon 添加 编程 一个 删除      更新时间:2023-10-16

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

然而,当我切换视图时,我希望能够以编程方式删除按钮和分隔符,但我不确定如何去做,到目前为止,我有类似于以下的东西(伪代码):

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元素?

提前感谢!

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

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