参考了MFC源码,继承CMFCRibbonStatusBarPane,重写OnDraw虚函数,实现字体颜色和图标的切换。
成都创新互联是一家专注于成都做网站、成都网站建设与策划设计,凉城网站建设哪家好?成都创新互联做网站,专注于网站建设10多年,网设计领域的专业建站公司;建站业务涵盖:凉城等地区。凉城做网站价格咨询:028-86922220
//.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();
网页名称:重写CMFCRibbonStatusBarPane类
文章路径:https://www.cdcxhl.com/article36/psoesg.html
成都网站建设公司_创新互联,为您提供标签优化、用户体验、手机网站建设、外贸网站建设、App开发、网站维护
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联