Search code examples
mfcwindows-ribbon-framework

How can I redraw the ribbon UI Elements


I am doing a MFC Ribbon programming based on MDI environments.

I want to change the elements of the MFC Ribbon gallery button on runtime.

So I create a HBITMAP objects on runtime and using SetPallete method in CMFCToolBarImage class.

My code is below.

CMFCRibbonGallery* pGallery = (CMFCRibbonGallery*)pRibbon->FindByID(ID_BUTTON_LABEL_CONTROL_GALLERY);
CMFCToolBarImages test;
test.SetImageSize(t);
test.AddImage(hBitmap, 0);
pGallery->Clear();
pGallery->SetPalette(test);
pGallery->RedrawIcons();

When i run this code, the ribbon gallery button is deleted, but there is no elements in the gallery button.

Strange thing is when I Minimize/Maximize the window, The Icons are visible at the button.

How can Icons are visible without minimize/maximize the window? Thanks you.


Solution

  • Try and call CMFCRibbonBar::RecalcLayout, this function forces the complete ribbon layout to be recalculated and redrawn.