1

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?

cbuchart
  • 10,847
  • 9
  • 53
  • 93
foraidt
  • 5,519
  • 5
  • 52
  • 80

3 Answers3

4

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

m_wndStatusBar.ForceRecalcLayout();
demoncodemonkey
  • 11,730
  • 10
  • 61
  • 103
1

use the CMFCRibbonStatusBarPane::SetAlmostLargeText function

0

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();
}
Community
  • 1
  • 1
foraidt
  • 5,519
  • 5
  • 52
  • 80