Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Display colored text on Status Bar

0.00/5 (No votes)
23 May 2002 1  
An article with code on displaying colored text on panes in a Status Bar using MFC

Sample Image - colorstatusbar.jpg

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.

  1. In MainFrm.h, the following line is inserted before the class definition
  2. #include "ColoredStatusBarCtrl.h"
  3. Now look for following line
  4. CStatusBar m_wndStatusBar;

    Its class type is changed to 

    CColoredStatusBarCtrl m_wndStatusBar;
  5. In MainFrm.cpp, look for following array declaration 
  6. 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.

  7. Now in CMainFrame::OnCreate(), I inserted the following code before the return statement:
  8. 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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here