Click here to Skip to main content
15,499,802 members
Articles / Desktop Programming / MFC
Posted 21 Jan 2001


76 bookmarked

Enhanced Progress Bar Control

Rate me:
Please Sign up or sign in to vote.
4.88/5 (28 votes)
11 Jun 2002CPOL
An enhanced progress control that supports gradient shading, formatted text, animation, tooltips, shape, 'snake' and reverse modes, and vertical modes

You can find the latest version and some other code on my Home Page.

Sample Image - ProgressCtrlX.gif


In this article I want to introduce an enhanced ProgressBar control. I collected some ideas from articles on CodeGuru and CodeProject, added some ideas of my own and developed this control. I tried to develop it in the most common, flexible and extensible way. From version 1.3 the control is separated into 3 different classes: CGradient -> CProgress -> CProgressCtrlX. Class CGradient encapsulates gradient drawing functionality. CProgress is a non-window version of the progress control. It supports nearly all the functionality of the progress bar and can be used separately. CProgressCtrlX is a MFC progress bar based control that is also derived from CProgress.


  • Filling with gradient colors
  • Multi-color gradient (unlimited number of colors)
  • Rubber gradient
  • Filling with brush for background and progress indicator (overrides color settings)
  • Text on bar
  • Dual color for text
  • Any angle text rotation (PBT_ANY_ANGLE) or 0-90-180-270 degree text rotation (w/o PBT_ANY_ANGLE)
  • Text alignment (right, left, top, bottom, centered, vertical centered)
  • Font settings support
  • Formatted text (can show percent, position or plain text)
  • Text tied to progress indicator
  • Support for vertical oriented control
  • Reverse mode
  • Snake mode
  • Borders
  • Shaped mode (Use CRgnX from sample to create rgn from bitmap and text)
  • ToolTip with text formatting
  • Palette support for 256 colors mode (optional)
  • Gradient Animation and Stretching
  • ...........

Advanced Interface:

Text Alignment (to set text alignment styles use SetTextAlign)

#define PBS_LEFT                 0x0010L
#define PBS_RIGHT                0x0020L
#define PBS_CENTER               0x0030L
#define PBS_TOP                  0x0040L
#define PBS_BOTTOM               0x0080L
#define PBS_VCENTER              0x00C0L

Text Format (to set text format use SetTextFormat and HideText):

#define PBS_SHOW_PERCENT         0x0100
#define PBS_SHOW_POSITION        0x0200
#define PBS_SHOW_TEXTONLY        0x0300

Control Styles (use ModifyBarStyle or appropriated functions):

#define PBS_TIED_TEXT        0x1000
#define PBS_RUBBER_BAR       0x2000
#define PBS_REVERSE          0x4000
#define PBS_SNAKE            0x8000

Advanced functionality:

	void SetStretchGradient(float flStretchFactor = 1); // useful for animation
	float GetStretchGradient();

	void SetGradientColors(COLORREF clrStart, COLORREF clrEnd); void
	GetGradientColors(COLORREF& clrStart, COLORREF&  clrEnd);

	void SetGradientColorsX(int nCount, COLORREF clrFirst, COLORREF  clrNext, ...); 
	const CDWordArray& GetGradientColorsX();
	void AddColor(COLORREF clr);

	void SetCreatePalette(BOOL fCreate =TRUE); 
	BOOL GetCreatePalette();
	CPalette& GetPalette(); 

	void SetBarBrush(CBrush* pbrBar);
	CBrush* GetBarBrush();

	void SetBkColor(COLORREF clrBk);
	COLORREF GetBkColor();

	void SetBkBrush(CBrush* pbrBk);
	CBrush* GetBkBrush();

	void SetTextColor(COLORREF clrTextOnBar, COLORREF clrTextOnBk = -1);
	COLORREF GetTextColor();
	COLORREF GetTextColorOnBk();

	void SetShowPercent(BOOL fShowPercent = TRUE);
	BOOL GetShowPercent();

	void SetTextAlign(DWORD dwStyle);
	DWORD GetTextAlign();

	void SetTextFormat(LPCTSTR szFormat, DWORD ffFormat = PBS_SHOW_TEXTONLY);
	void HideText();

	void SetTiedText(BOOL fTiedText = TRUE);
	BOOL GetTiedText();

	void SetRubberBar(BOOL fRubberBar = TRUE);
	BOOL GetRubberBar();

	void SetReverse(BOOL fReverse = TRUE);
	BOOL GetReverse();

	void SetSnake(BOOL fSnake = TRUE);
	BOOL GetSnake();

	void SetSnakeTail(int nTailSize);
	int  GetSnakeTail();

	void SetBorders(const CRect& rcBorders);
	const CRect& GetBorders();

	void SetShape(HBITMAP hBmp, COLORREF clrTransparent = 0);

	void SetRange(int nLower, int nUpper);
	void GetRange(int& nLower, int& nUpper);

	int GetPos() {return m_nPos;}
	int SetPos(int nPos);

	int OffsetPos(int nIncrement);

	int SetStep(int nStep);

	int StepIt();

	void SetFont(CFont* pFont);
	CFont* GetFont();

	void Draw(CDC* pDC, CRect rcDraw, BOOL fSkipDCCache = FALSE);

	virtual DWORD GetBarStyle();
	virtual void ModifyBarStyle(DWORD dwRemove, DWORD dwAdd);

	void Animate(int nStep);
	void ResetAnimation();

	void SetTooltipFormat (LPCTSTR lpszToolTipText, DWORD fFormat = PBS_SHOW_TEXTONLY);
	LPCTSTR GetTooltipText();
	void HideTooltip();
	void RunSnake(int nMsPerStep);
	void StopSnake();

	void RunAnimation(int nMsPerStep, int nStep);
	void StopAnimation();

You can use:

  • SetFont() - to set font and rotation(Escapement) of the text
  • SetStyle(), ModifyStyle(), SetBarStyle(), ModifyBarStyle() - to change styles of control
  • Any functionality of base class CProgressCtrl

See Test Project for additional information on usage.


The best views and performance is got on HighColor(15/16 bit) and TrueColor(24/32 bit) resolutions. Control also supports 256 and 16 color modes. However, in 16 colors mode you cannot use gradient, and in 256 colors mode the control works slower because of usage of CreateSolidBrush/FillRect instead of FillSolidRect.

If you want rotate text to any angle - define PBT_ANY_ANGLE and recompile control.

Control is part of UIBits.dll and independent usage requires additional files: DrawGdiX.h, MemDC.h


January 21, 2001 - version 1.4

  • Gradient Animation and stretching added
  • Fixed some bugs from previous version

January 10, 2001 - version 1.3

  • Code separated to three classes CGradient, CProgress and CProgressCtrlX
  • Added tooltips with text formatting
  • Added self running snake
  • Added palette support for 256 colors mode
  • Added shaped style drawing

September 20, 2000 - version 1.2

  • Added support for "Any angle text rotation"
    (define PBT_ANY_ANGLE and set font with appropriated angle)
  • Added text alignment
  • Added possibility to format text (via virtual function FormatText())
    e.g. you can show percent as decimal fraction instead of integer
  • Some code improvements

August 2, 2000 - version 1.1

  • Added multi-color gradient
  • Added filling with brush for background and bar (overrides color settings)
  • Added borders attribute
  • Added vertical text support
  • Added snake mode
  • Added reverse mode
  • Added dual color for text
  • Added text formatting
  • Added tied mode for text and rubber bar mode
  • Added support for vertical oriented control (PBS_VERTICAL)

June 5, 2000 - version 1.0

You can find the latest version and some other code on my Home Page.


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

Written By
Software Developer (Senior)
Israel Israel
Yury is Software Engineer since 1988.
His programming experience includes C#/VB.NET, WPF, C/C++(MFC/STL), Borland Delphi & C++ (VCL), JavaScript, HTML, CSS, XML, SQL, VB6, DirectX, Flash.
He has worked on PCs (DOS/Win3.1-Vista) and PocketPCs (WinCE).

Yury was born in Ukraine, but currently based in Jerusalem.

Comments and Discussions

QuestionThanks for sharing Pin
bosfan28-Nov-13 1:07
Memberbosfan28-Nov-13 1:07 
Hi for first thanks for sharing your work. Thumbs Up | :thumbsup:
Now i have a question, there is an (more then one) error with the function:
SetBkColor(..) maybe because she is in twice classes present with the same name?
Error Message :
progressctrlx.cpp(132): error C2385: ambiguous access of 'SetBkColor'

I use VS 2010, maybe you can help to fix this issue?

Thanks for all.
AnswerRe: Thanks for sharing Pin
Yury Goltsman28-Nov-13 1:25
MemberYury Goltsman28-Nov-13 1:25 
GeneralGreat progress bar and scles on it Pin
George papas20-Aug-10 4:27
MemberGeorge papas20-Aug-10 4:27 
GeneralRe: Great progress bar and scles on it Pin
Yury Goltsman21-Aug-10 21:59
MemberYury Goltsman21-Aug-10 21:59 
GeneralA little problem under Windows XP theme [modified] Pin
chocm12-Jan-09 1:04
Memberchocm12-Jan-09 1:04 
GeneralRe: A little problem under Windows XP theme Pin
Yury Goltsman12-Jan-09 3:18
MemberYury Goltsman12-Jan-09 3:18 
GeneralSome questions Pin
ElClassico16-Nov-07 12:55
MemberElClassico16-Nov-07 12:55 
GeneralRe: Some questions Pin
Yury Goltsman18-Nov-07 10:17
MemberYury Goltsman18-Nov-07 10:17 
QuestionRubber bar? Pin
ElClassico16-Nov-07 12:48
MemberElClassico16-Nov-07 12:48 
AnswerRe: Rubber bar? Pin
Yury Goltsman18-Nov-07 10:06
MemberYury Goltsman18-Nov-07 10:06 
GeneralWorks great Pin
copernican20-Sep-06 12:49
Membercopernican20-Sep-06 12:49 
QuestionHow to refresh the updated position?? [modified] Pin
pavanbabut18-Jul-06 8:25
Memberpavanbabut18-Jul-06 8:25 
AnswerRe: How to refresh the updated position?? Pin
Yury Goltsman18-Jul-06 9:20
MemberYury Goltsman18-Jul-06 9:20 
QuestionHow can I use it in a status bar Pin
Golden Lee22-Jul-05 18:22
MemberGolden Lee22-Jul-05 18:22 
QuestionProblem with slower/older systems? Pin
Sims1-Sep-04 0:03
MemberSims1-Sep-04 0:03 
AnswerRe: Problem with slower/older systems? Pin
Yury Goltsman1-Sep-04 1:27
MemberYury Goltsman1-Sep-04 1:27 
GeneralUsing this control in VB.NET Pin
Virgil Reboton15-Jun-04 23:27
MemberVirgil Reboton15-Jun-04 23:27 
QuestionWindows XP / 2003? Pin
Christoph Lederer16-Mar-04 22:19
MemberChristoph Lederer16-Mar-04 22:19 
AnswerRe: Windows XP / 2003? Pin
Alexander Shevchenko10-Jun-04 10:02
MemberAlexander Shevchenko10-Jun-04 10:02 
QuestionHow can clear the borden around the control window? Pin
shinypro9-Mar-04 14:53
Membershinypro9-Mar-04 14:53 
AnswerRe: How can clear the borden around the control window? Pin
shinypro9-Mar-04 14:53
Membershinypro9-Mar-04 14:53 
AnswerRe: How can clear the borden around the control window? Pin
g2internet20-Jul-04 3:38
Memberg2internet20-Jul-04 3:38 
GeneralThis is great. Pin
cdesylva7-Feb-03 7:30
Membercdesylva7-Feb-03 7:30 
GeneralGood work, but your demo project can not compile it with the .NET-Compiler. Pin
andy_lfx21-Jul-02 1:11
Memberandy_lfx21-Jul-02 1:11 
GeneralRe: Good work, but your demo project can not compile it with the .NET-Compiler. Pin
Yury Goltsman18-Feb-04 3:43
MemberYury Goltsman18-Feb-04 3:43 

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.