Click here to Skip to main content
15,879,095 members
Articles / Desktop Programming / MFC
Article

Display colored text on Status Bar

Rate me:
Please Sign up or sign in to vote.
4.41/5 (11 votes)
23 May 20021 min read 162.4K   4.4K   28   22
An article with code on displaying colored text on panes in a Status Bar using MFC

Image 1

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


Written By
Software Developer
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 3 Pin
wolfgangpuelm29-Sep-10 5:46
professionalwolfgangpuelm29-Sep-10 5:46 
GeneralRe: My vote of 3 Pin
The Code Machine13-Oct-10 19:39
The Code Machine13-Oct-10 19:39 
QuestionDear Pin
teth3-Feb-08 22:13
teth3-Feb-08 22:13 
GeneralChange Color based on Error Pin
NYTSX3-May-06 4:32
NYTSX3-May-06 4:32 
GeneralRe: Change Color based on Error Pin
The Code Machine24-Aug-06 6:18
The Code Machine24-Aug-06 6:18 
GeneralBrilliat !! Pin
Alton Williams21-Jun-05 2:53
Alton Williams21-Jun-05 2:53 
GeneralResource problem Pin
shrinivasbk7-Jul-04 1:37
shrinivasbk7-Jul-04 1:37 
QuestionHow to add to Dialog Box Pin
mistroseth7-Apr-03 9:57
mistroseth7-Apr-03 9:57 
GeneralI have completed it, and it works well with SetPaneText member function Pin
cadinfo10-Nov-02 2:32
cadinfo10-Nov-02 2:32 
GeneralRe: I have completed it, and it works well with SetPaneText member function Pin
vikas amin25-Aug-05 23:41
vikas amin25-Aug-05 23:41 
QuestionWhat about SetPaneText() Pin
spentaro15-Jul-02 19:41
spentaro15-Jul-02 19:41 
AnswerRe: What about SetPaneText() Pin
The Code Machine15-Jul-02 20:53
The Code Machine15-Jul-02 20:53 
GeneralRe: What about SetPaneText() Pin
spentaro16-Jul-02 8:30
spentaro16-Jul-02 8:30 
GeneralRe: What about SetPaneText() Pin
The Code Machine16-Jul-02 20:53
The Code Machine16-Jul-02 20:53 
GeneralI do something like this,very good to use! Pin
lilyflower5-Aug-02 22:36
lilyflower5-Aug-02 22:36 
Generala little change,but no twinkle(status bar) Pin
mclxly5-Dec-06 16:42
mclxly5-Dec-06 16:42 
QuestionRe: I do something like this,very good to use! Pin
xu_qing14-Mar-07 6:15
xu_qing14-Mar-07 6:15 
AnswerRe: I do something like this,very good to use! Pin
The Code Machine21-Mar-07 15:10
The Code Machine21-Mar-07 15:10 
GeneralRe: I do something like this,very good to use! Pin
rbrunton8-Feb-15 1:47
rbrunton8-Feb-15 1:47 
GeneralRe: What about SetPaneText() Pin
bkshrinivas7-Jun-04 1:45
bkshrinivas7-Jun-04 1:45 
AnswerRe: What about SetPaneText() Pin
Dbltrimmer30-Oct-05 7:36
Dbltrimmer30-Oct-05 7:36 
GeneralVery very important, Onkar Singh tread this!!!! Pin
4-Jun-02 12:06
suss4-Jun-02 12:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.