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

//.h文件内容
#pragma once
#include "afxribbonstatusbarpane.h"
#include "MemDC.h"
class CScale3DCStatusBarPanel : public CMFCRibbonStatusBarPane
{
public:
CScale3DCStatusBarPanel(
UINT nCmdID, // Pane command id
LPCTSTR lpszText, // Pane label
BOOL bIsStatic = FALSE, // Pane is static (non-clickable)
HICON hIcon = NULL, // Pane icon
LPCTSTR lpszAlmostLargeText = NULL);// The almost large text in pane
~CScale3DCStatusBarPanel();
virtual void OnDraw(CDC* pDC);
protected:
BOOL m_bIsOpen = TRUE; //是否显示红色字体
public:
void SetTextColor(BOOL bIsValue = FALSE); //设置字体颜色
};
//.cpp文件内容
#include "stdafx.h"
#include "Scale3DCStatusBarPanel.h"
#include "resource.h"
CScale3DCStatusBarPanel::CScale3DCStatusBarPanel(
UINT nCmdID, LPCTSTR lpszText, BOOL bIsStatic,
HICON hIcon, LPCTSTR lpszAlmostLargeText
)
{
CommonInit();
//父类成员变量
m_strAlmostLargeText =
(lpszAlmostLargeText == NULL) ? _T("") : lpszAlmostLargeText;
m_bIsStatic = bIsStatic;
m_strText = lpszText;
m_bIsOpen = FALSE;//自定义成员变量
}
void CScale3DCStatusBarPanel::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);
}
void CScale3DCStatusBarPanel::SetTextColor(BOOL bValue)
{
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();
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
本文标题:重写CMFCRibbonStatusBarPane类-创新互联
转载来源:http://www.jxjierui.cn/article/depheg.html


咨询
建站咨询
