您好,登錄后才能下訂單哦!
參考了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();
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。