views:

415

answers:

3

My CMDIFrameWndEx derived main frame window uses a CMFCRibbonStatusBar to which I add a CMFCRibbonLabel. I'd like to change the text of this label at runtime:

m_pLabel->SetText(description);
m_pLabel->Redraw();

It only updates the text but not the rectangle in which to draw it. So if the original text was too short, the new string won't be visible completely.

How do I get it to resize correctly?

A: 

Answering my own question again...

I worked around the issue by adding and removing the label instead of trying to change the text.

Code for adding the label:

CMFCRibbonLabel* pLabel = new CMFCRibbonLabel(description);
pLabel->SetID(ID_MYLABEL); // ID is 0 by default

m_wndStatusBar.AddDynamicElement(pLabel);
m_wndStatusBar.RecalcLayout();
m_wndStatusBar.RedrawWindow();

Note that I'm setting an ID so I can later call CMFCRibbonStatusBar::RemoveElement() with that ID. The calls to RecalcLayout() and RedrawWindow() are needed to make the changes visible.

Code for removing the label:

if(m_wndStatusBar.RemoveElement(ID_MYLABEL))
{
    m_wndStatusBar.RecalcLayout();
    m_wndStatusBar.RedrawWindow();
}
mxp
+1  A: 

use the CMFCRibbonStatusBarPane::SetAlmostLargeText function

A: 

You don't need to remove and re-add. Just call this:

m_wndStatusBar.ForceRecalcLayout();
demoncodemonkey