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
#include "ColoredStatusBarCtrl.h"
- Now look for following line
CStatusBar m_wndStatusBar;
Its class type is changed to
CColoredStatusBarCtrl m_wndStatusBar;
- In MainFrm.cpp, look for following array declaration
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.
- Now in
CMainFrame::OnCreate()
, I inserted the following code before the
return
statement:
for (int i=0; i<4; i++)
{
m_wndStatusBar.GetStatusBarCtrl().SetText("", i, SBT_OWNERDRAW);
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.