我正在编写一个利用功能区栏的 MFC 应用程序,我已经在功能区编辑器中设计了大部分应用程序。但是,对于我的一个 View ,我需要以编程方式添加一些按钮,并且我想在它们之间添加一个分隔符。
但是,当我随后切换 View 时,我希望能够以编程方式删除按钮和分隔符,但我不确定如何去做,到目前为止我有类似于以下内容的内容(伪代码):
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 );
关于c++ - 在 MFC 功能区栏中删除以编程方式添加的面板分隔符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16999658/