Click here to Skip to main content
Licence 
First Posted 23 May 2002
Views 115,800
Bookmarked 25 times

Display colored text on Status Bar

By | 23 May 2002 | Article
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

About the Author

The Code Machine

Software Developer

India India

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 3 Pinmemberwolfgangpuelm5:46 29 Sep '10  
GeneralRe: My vote of 3 PinmemberThe Code Machine19:39 13 Oct '10  
QuestionDear Pinmemberteth22:13 3 Feb '08  
GeneralChange Color based on Error PinmemberNYTSX4:32 3 May '06  
GeneralRe: Change Color based on Error PinmemberThe Code Machine6:18 24 Aug '06  
GeneralBrilliat !! PinmemberAlton Williams2:53 21 Jun '05  
GeneralResource problem Pinmembershrinivasbk1:37 7 Jul '04  
QuestionHow to add to Dialog Box Pinmembermistroseth9:57 7 Apr '03  
GeneralI have completed it, and it works well with SetPaneText member function Pinmembercadinfo2:32 10 Nov '02  
GeneralRe: I have completed it, and it works well with SetPaneText member function Pinmembervikas amin23:41 25 Aug '05  
QuestionWhat about SetPaneText() Pinmemberspentaro19:41 15 Jul '02  
AnswerRe: What about SetPaneText() PinmemberOnkar Singh20:53 15 Jul '02  
GeneralRe: What about SetPaneText() PinsussJ. Spencer Greene8:30 16 Jul '02  
GeneralRe: What about SetPaneText() PinmemberOnkar Singh20:53 16 Jul '02  
GeneralI do something like this,very good to use! Pinsusslilyflower22:36 5 Aug '02  
Generala little change,but no twinkle(status bar) Pinmembermclxly16:42 5 Dec '06  
QuestionRe: I do something like this,very good to use! Pinmemberxu_qing6:15 14 Mar '07  
AnswerRe: I do something like this,very good to use! PinmemberThe Code Machine15:10 21 Mar '07  
GeneralRe: What about SetPaneText() Pinmemberbkshrinivas1:45 7 Jun '04  
AnswerRe: What about SetPaneText() PinmemberDbltrimmer7:36 30 Oct '05  
GeneralVery very important, Onkar Singh tread this!!!! PinmemberAnonymous12:06 4 Jun '02  

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

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

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120528.1 | Last Updated 24 May 2002
Article Copyright 2002 by The Code Machine
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid