参考了MFC源码,继承CMFCRibbonStatusBarPane,重写OnDraw虚函数,实现字体颜色和图标的切换。

//.h文件内容#pragmaonce#include"afxribbonstatusbarpane.h"#include"MemDC.h"classCScale3DCStatusBarPanel:publicCMFCRibbonStatusBarPane{public:CScale3DCStatusBarPanel(UINTnCmdID,//PanecommandidLPCTSTRlpszText,//PanelabelBOOLbIsStatic=FALSE,//Paneisstatic(non-clickable)HICONhIcon=NULL,//PaneiconLPCTSTRlpszAlmostLargeText=NULL);//Thealmostlargetextinpane~CScale3DCStatusBarPanel();virtualvoidOnDraw(CDC*pDC);protected:BOOLm_bIsOpen=TRUE;//是否显示红色字体public:voidSetTextColor(BOOLbIsValue=FALSE);//设置字体颜色};//.cpp文件内容#include"stdafx.h"#include"Scale3DCStatusBarPanel.h"#include"resource.h"CScale3DCStatusBarPanel::CScale3DCStatusBarPanel(UINTnCmdID,LPCTSTRlpszText,BOOLbIsStatic,HICONhIcon,LPCTSTRlpszAlmostLargeText){CommonInit();//父类成员变量m_strAlmostLargeText=(lpszAlmostLargeText==NULL)?_T(""):lpszAlmostLargeText;m_bIsStatic=bIsStatic;m_strText=lpszText;m_bIsOpen=FALSE;//自定义成员变量}voidCScale3DCStatusBarPanel::OnDraw(CDC*pDC){ASSERT_VALID(this);ASSERT_VALID(pDC);if(m_rect.IsRectEmpty()){return;}else{m_rt.CopyRect(m_rect);}OnFillBackground(pDC);pDC->SetTextColor(RGB(21,66,139));pDC->DrawText(m_strText,m_rect,DT_LEFT);OnDrawBorder(pDC);}voidCScale3DCStatusBarPanel::SetTextColor(BOOLbValue){m_bIsOpen=bValue;}

调用方法如下:
m_wndStatusBar.AddElement(new CScale3DCStatusBarPanel(ID_STATUSBAR_PANE4, strComWork + strComWork1 + _T("(0)"), TRUE), strComWork);

CScale3DCStatusBarPanel* pElem = (CScale3DCStatusBarPanel*)m_wndStatusBar.GetElement(7);

pElem->SetAlmostLargeText(_T("........................................"));

pElem->Redraw();