Thomas Russell
Thomas Russell

Reputation: 5980

Removing a programmatically added panel separator in MFC Ribbon Bar

I am writing an MFC application which takes advantage of the Ribbon bar, and I've designed most of it in the Ribbon editor. However, for one of my views, I need to programmatically add some buttons, and I would like to add a separator between them.

However, when I then switch views I want to be able to programmatically remove the buttons and the separator, but I'm not sure how to go about it, so far I have something similar to the following (pseudocode):

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:
}

Is there a function I can call to delete the separator, or should I treat it as a normal Ribbon element?

Thanks in advance!

Upvotes: 0

Views: 1694

Answers (1)

Edward Clements
Edward Clements

Reputation: 5142

Treat the separator as a normal Ribbon element, it is just another class (CMFCRibbonSeparator) derived from the CMFCRibbonBaseElement class:

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

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

Upvotes: 1

Related Questions