Display colored text on Status Bar






4.41/5 (10 votes)
May 24, 2002
1 min read

164365

4454
An article with code on displaying colored text on panes in a Status Bar using MFC
Introduction
I wondered how to change text color of panes on the status bar same as what Visual SourceSafe file difference window does. In this article, I will show how to make status bar panes display their text in different colors. A regular status bar can have many panes. It could be desirable in some cases that each pane's text could be displayed in a different color.
If you open the demo project file in Visual C++, you will see two new files,
namely ColoredStatusBarCtrl.cpp and ColoredStatusBarCtrl.h. CColoredStatusBarCtrl
wraps the owner-drawn capability of CStatusBar
MFC class.
Besides above stuff, you could see some changes in MainFrm.cpp and MainFrm.h.
- In MainFrm.h, the following line is inserted before the class definition
- Now look for following line
- In MainFrm.cpp, look for following array declaration
- Now in
CMainFrame::OnCreate()
, I inserted the following code before thereturn
statement:
#include "ColoredStatusBarCtrl.h"
CStatusBar m_wndStatusBar;
Its class type is changed to
CColoredStatusBarCtrl m_wndStatusBar;
static UINT indicators[] =
{
ID_1,
ID_2,
ID_3,
ID_4,
};
I created empty entries in string table for above ids. They will just stay there doing nothing.
for (int i=0; i<4; i++) { // Change Status Bar style to make it Owner-drawn m_wndStatusBar.GetStatusBarCtrl().SetText("", i, SBT_OWNERDRAW); // Make each pane's of same size m_wndStatusBar.SetPaneInfo( i, m_wndStatusBar.GetItemID(i), SBPS_STRETCH, NULL ); }
Limitation
CColoredStatusBarCtrl
is not generic. You may need to tweak it to
make it workable for you. It just makes the point. I wish I could write a
control for it.