Click here to Skip to main content
11,412,516 members (66,307 online)
Click here to Skip to main content

Showing progress bar in a status bar pane

, 23 Aug 2010 CPOL
Rate this:
Please Sign up or sign in to vote.
An easy way to add a progress control to a status bar

Sample Image

Adding a CProgressCtrl to the status bar has already been addressed by Brad Mann. His method involved modifying the status bar and messing around with the resource editor. I developed a separate CProgressBar class in order to allow the programmer to just drop in a progress bar whereever they wanted using a single "CProgressBar Bar(...)" declaration, which would initialise and display itself and clean up after itself after it was done. The progress bar can also be created once (say as a member variable) and reused multiple times. This new version of the progress bar also resizes itself if the status bar size changes.

The progress bar lets you specify a message (displayed to the left of the bar) and a Progress Control bar in the any pane of your applications status bar (if it has one - thanks to Patty You for a bug fix on that one). The message for the progress bar can be changed at any time, as can the size and range of the bar.


CProgressBar(LPCTSTR strMessage, int nSize=100, int MaxValue=100, BOOL bSmooth=FALSE, int nPane=0);
BOOL Create(LPCTSTR strMessage, int nSize=100, int MaxValue=100, BOOL bSmooth=FALSE, int nPane=0);

Construction is either via the constructor or a two-step process using the constructor and the "Create" function. "strMessage" is the message to be displayed, "nSize" is the percentage width of the status bar that will be occupied by the bar (including the text), and "MaxValue" is the maximum range of the bar.

"bSmooth" will only be effective if you have the header files and commctrl32.dll from IE 3.0 or above (no problems for MS VC 5.0). It specifies whether the progress bar will be smooth or chunky.


    BOOL Success()                      // Construction successful?

    COLORREF SetBarColour(COLORREF clrBar);  // Set Bar colour, returns previous
    COLORREF SetBkColour(COLORREF clrBar);   // Set background colour, returns previous

    int  SetPos(int nPos);              // Same as CProgressCtrl
    int  OffsetPos(int nPos);           // Same as CProgressCtrl
    int  SetStep(int nStep);            // Same as CProgressCtrl
    int  StepIt();                      // Same as CProgressCtrl
    void Clear();                       // Clear the status bar
    void SetRange(int nLower, int nUpper, int nStep = 1);
                                        // Set min, max and step size
    void SetText(LPCTSTR strMessage);   // Set the message
    void SetSize(int nSize);            // Set the bar size

To use the bar, just do something like:

    CProgressBar Bar("Testing", 40, 1000);
    for (int i = 0;  i <  1000; i++) 
        // perform operation
or it can be done two stage as:
    CProgressBar bar;
    bar.Create("Processing", 40, 1000);
    for (int i = 0; i < 1000; i++) 
        //    perform operation 
    for  (int i = 0;  i <  1000; i++) 
        // perform operation
        PeekAndPump();    // Message pump

In the above case, PeekAndPump() is a function which simply peeks and pumps messages, allowing user interaction with the window during a lengthy process. If the window size changes during the processing, the progress bar size will alsow change.

This article was updated by Michael Martin (allowing the progress bar can now be placed in any pane of the status bar). A further update by YoSilver has fixed an issue that occurs in multithreaded apps. Yet Another Update by Alex Paterson allows you to specify which statusbar you wish the bar to appear in.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Chris Maunder
Founder CodeProject
Canada Canada
Chris is the Co-founder, Administrator, Architect, Chief Editor and Shameless Hack who wrote and runs The Code Project. He's been programming since 1988 while pretending to be, in various guises, an astrophysicist, mathematician, physicist, hydrologist, geomorphologist, defence intelligence researcher and then, when all that got a bit rough on the nerves, a web developer. He is a Microsoft Visual C++ MVP both globally and for Canada locally.

His programming experience includes C/C++, C#, SQL, MFC, ASP, ASP.NET, and far, far too much FORTRAN. He has worked on PocketPCs, AIX mainframes, Sun workstations, and a CRAY YMP C90 behemoth but finds notebooks take up less desk space.

He dodges, he weaves, and he never gets enough sleep. He is kind to small animals.

Chris was born and bred in Australia but splits his time between Toronto and Melbourne, depending on the weather. For relaxation he is into road cycling, snowboarding, rock climbing, and storm chasing.
Follow on   Twitter   Google+   LinkedIn

Comments and Discussions

QuestionProgress Bar in Web Application Pin
akjha16 at 17-Sep-14 1:33
memberakjha1617-Sep-14 1:33 
QuestionCan't extract the demo Pin
Ron Anders at 23-Jan-13 18:54
memberRon Anders23-Jan-13 18:54 
QuestionCorrelating "range" with time? Pin
Vaclav_Sal at 24-May-12 6:38
memberVaclav_Sal24-May-12 6:38 
QuestionAwesome Pin
Andy Bantly at 11-Mar-12 10:48
memberAndy Bantly11-Mar-12 10:48 
QuestionIt doesn't work with SetCapture() Pin
Plamen Petrov at 29-Dec-11 22:10
memberPlamen Petrov29-Dec-11 22:10 
GeneralMy vote of 5 Pin
Mei You Qian at 18-Aug-11 7:23
memberMei You Qian18-Aug-11 7:23 
GeneralMy vote of 5 Pin
koothkeeper at 20-Apr-11 5:19
memberkoothkeeper20-Apr-11 5:19 
GeneralMy vote of 5 Pin
wud97181d at 30-Dec-10 16:31
memberwud97181d30-Dec-10 16:31 
GeneralAwesome! Pin
Ernest Laurentin at 28-Aug-10 11:51
memberErnest Laurentin28-Aug-10 11:51 
GeneralDirectives/libraries Pin
wmedwardc at 21-Sep-09 21:42
memberwmedwardc21-Sep-09 21:42 
QuestionVC6? Pin
basementman at 15-Jul-09 11:56
memberbasementman15-Jul-09 11:56 
GeneralThanks! Pin
ccaprani at 4-Aug-08 10:01
memberccaprani4-Aug-08 10:01 
GeneralThank you Pin
Member 3092688 at 2-Apr-08 9:30
memberMember 30926882-Apr-08 9:30 
GeneralI want to use your progress bar to my directx program Pin
akira32 at 28-Jul-07 21:13
memberakira3228-Jul-07 21:13 
GeneralThanks for showing me how to set the colour Pin
Owen Lawrence at 21-Mar-07 11:16
memberOwen Lawrence21-Mar-07 11:16 
GeneralRe: Thanks for showing me how to set the colour Pin
chenjieming at 10-Jul-10 0:03
memberchenjieming10-Jul-10 0:03 
NewsSerious bug! Pin
YoSilver at 4-Mar-07 6:06
memberYoSilver4-Mar-07 6:06 
GeneralRe: Serious bug! Pin
Joseph Mccornell at 7-Feb-08 23:47
memberJoseph Mccornell7-Feb-08 23:47 
GeneralRe: Serious bug! Pin
Damir Valiulin at 13-Jul-09 11:20
memberDamir Valiulin13-Jul-09 11:20 
GeneralRe: Serious bug! Pin
Chris Maunder at 15-Jul-09 5:16
adminChris Maunder15-Jul-09 5:16 
GeneralRe: Serious bug! Pin
Damir Valiulin at 15-Jul-09 8:37
memberDamir Valiulin15-Jul-09 8:37 
GeneralAbout InterAction Pin
wzh19831221 at 10-Dec-06 16:37
memberwzh1983122110-Dec-06 16:37 
Generalint GetSize() Pin
mimosa at 30-Apr-06 13:18
membermimosa30-Apr-06 13:18 
QuestionAdding snake feature to the control ? Pin
jongallegraud at 19-Mar-06 23:03
memberjongallegraud19-Mar-06 23:03 
GeneralDoesn't seem to work for dialog status bar Pin
TobyNorris at 2-Feb-06 5:56
memberTobyNorris2-Feb-06 5:56 
GeneralThanks Pin
David.Kelly at 7-Nov-05 9:08
memberDavid.Kelly7-Nov-05 9:08 
GeneralRe: Thanks Pin
Chris Maunder at 7-Nov-05 9:09
adminChris Maunder7-Nov-05 9:09 
General! Bug: Multiple Instances Pin
Synetech at 1-Jun-05 15:37
memberSynetech1-Jun-05 15:37 
GeneralUsing the CProgressBar in the Status Bar of a FormView Pin
Steve Mayfield at 4-Jan-05 16:35
memberSteve Mayfield4-Jan-05 16:35 
GeneralRe: Using the CProgressBar in the Status Bar of a FormView Pin
Tom Gee at 8-Jan-06 12:43
memberTom Gee8-Jan-06 12:43 
GeneralRe: Using the CProgressBar in the Status Bar of a FormView Pin
Tom Gee at 8-Jan-06 12:48
memberTom Gee8-Jan-06 12:48 
GeneralUsing With Pop3 Download Traffic Problem Pin
otrcomm at 11-Jul-04 10:33
memberotrcomm11-Jul-04 10:33 
GeneralUsing the progress bar in a CMDIChildWnd Pin
Melo at 18-Mar-04 10:11
memberMelo18-Mar-04 10:11 
GeneralDisplaying menu item prompt in a status bar Pin
toxcct at 4-Dec-03 4:03
membertoxcct4-Dec-03 4:03 
GeneralOh Good Pin
hyuckmin at 16-Nov-03 3:37
memberhyuckmin16-Nov-03 3:37 
Generalconnect progress bar with the process Pin
gravity_ok at 13-Oct-03 2:35
membergravity_ok13-Oct-03 2:35 
GeneralThanks.. Pin
small at 26-May-03 7:05
membersmall26-May-03 7:05 
GeneralBug: m_Rect not Initialized Pin
Matt Brunk at 8-Apr-03 22:01
memberMatt Brunk8-Apr-03 22:01 
GeneralRe: Bug: m_Rect not Initialized Pin
Anonymous at 14-Aug-03 7:35
sussAnonymous14-Aug-03 7:35 
GeneralProblem with changing size Pin
Jack_pt at 27-Mar-03 4:35
memberJack_pt27-Mar-03 4:35 
QuestionA solution in C#? Pin
LokivonAsgard at 27-Mar-03 0:45
memberLokivonAsgard27-Mar-03 0:45 
AnswerRe: A solution in C#? Pin
Alpha Nerd at 27-May-08 11:19
memberAlpha Nerd27-May-08 11:19 
GeneralMoving the Proogress...... Pin
Dilip Mathew at 12-Feb-03 22:24
sussDilip Mathew12-Feb-03 22:24 
GeneralRe: Moving the Proogress...... Pin
Jack_pt at 27-Mar-03 4:29
memberJack_pt27-Mar-03 4:29 
GeneralCompiler warnings with VC7 and /Wp64 switch Pin
C++ Hacker at 23-Jan-03 5:02
memberC++ Hacker23-Jan-03 5:02 
GeneralPeekAndPump Pin
loadcom at 24-Dec-02 16:01
memberloadcom24-Dec-02 16:01 
GeneralRe: PeekAndPump Pin
Dilip Mathew at 12-Feb-03 22:23
sussDilip Mathew12-Feb-03 22:23 
GeneralProgress bar Problem again Pin
Ken Le at 25-Jul-02 12:51
memberKen Le25-Jul-02 12:51 
GeneralInfinite Loop when using OpenGL drive Pin
Anonymous at 17-Apr-02 7:51
memberAnonymous17-Apr-02 7:51 
Generalusing the class as member variable Pin
Shahzad Khan at 8-Apr-02 11:15
memberShahzad Khan8-Apr-02 11:15 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150427.1 | Last Updated 23 Aug 2010
Article Copyright 1999 by Chris Maunder
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid