Click here to Skip to main content
12,699,214 members (24,562 online)
Click here to Skip to main content


73 bookmarked

Enhanced Progress Bar Control

, 11 Jun 2002 CPOL
An enhanced progress control that supports gradient shading, formatted text, animation, tooltips, shape, 'snake' and reverse modes, and vertical modes
<HEAD><TITLE>Enhanced ProgressBar Control</TITLE>
<META content="text/html; charset=iso-8859-1" http-equiv=Content-Type>
<META content="Yury Goltsman" name=Author>
<META content="Source code for various windows controls" name=description>
<META content="source code mfc visual c++ control windows" name=keywords>
content="Enhanced ProgressBar Control visual c++ free source code software downloads freeware shareware c++ web development general internet articles directory reference sample example help resource developer" 
<META content="Copyright � 1999-2000 Yury Goltsman, All Rights Reserved." name=Copyright>

type=text/css rel=stylesheet>
<h3 align="center"><font color="#a0a099">

Enhanced ProgressBar Control v1.4



<p><IMG alt="Sample Image" src="progressctrlx.gif" ></p>

<p><u>Environment:</u> VC6, NT4/9x</p>


<p>In this article I want to introduce enhanced ProgressBar control.
I collect some ideas from article 
on <a href="">CodeGuru</a> 
and <a href="">CodeProject</a>, add some my own ideas and develop this 
control. I try to develop it in most common, flexible and extensible 
way. From version 1.3 control separated to 3 different classes : <code>CGradient</code> 
-&gt; <code>CProgress</code> -&gt; <code>CProgressCtrlX</code>. Class <code>CGradient</code> encapsulates gradient 
drawing functionality. <code>CProgress</code> 
is non window version of progress control. 
It supports about all functionality of the progress and can be used
separately. <code>CProgressCtrlX</code> is MFC progress bar based control, that also derived from <code>CProgress</code>.

<LI>Filling with gradient colors
<LI>Multi-color gradient (unlimited number of colors)&nbsp;
<LI>Rubber gradient
<LI>Filling with brush for background and progress indicator (overrides color settings)
<LI>Text on bar
<LI>Dual color for text
<LI>Any angle text rotation (<code>PBT_ANY_ANGLE</code>) or 
  0-90-180-270 degree text rotation (w/o <code>PBT_ANY_ANGLE</code>)
<LI>Text alignment (right, left, top, bottom, centered, vertical centered)
<LI>Font settings support
<LI>Formatted text (can show percent, position or plain text)
<LI>Text tied to progress indicator
<LI>Support for vertical oriented control
<LI>Reverse mode
<LI>Snake mode
<LI>Shaped mode (Use CRgnX from sample to create rgn from bitmap and text)
<LI>ToolTip with text formatting
<LI>Palette support for 256 colors mode (optional) 
<LI>Gradient Animation and Stretching 
<H2>Advanced Interface:</H2>
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
<p>Advanced functionality: 
<pre > 
	void SetStretchGradient(float flStretchFactor = 1); // useful for animation
	float GetStretchGradient();

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

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

	void SetCreatePalette(BOOL fCreate =TRUE); 
	BOOL GetCreatePalette();
	CPalette&amp; 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&amp; rcBorders);
	const CRect&amp; GetBorders();

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

	void SetRange(int nLower, int nUpper);
	void GetRange(int&amp; nLower, int&amp; 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:
<LI><code>SetFont()</code> - to set font and <i>rotation</i>(Escapement) of the text
<LI><code>SetStyle(),ModifyStyle(),SetBarStyle(),ModifyBarStyle()</code> - to change styles of control
<LI>Any functionality of base class <code>CProgressCtrl</code></LI>
<P>See Test Project for additional information of usage.

<P>The best view and performance you can get on HighColor(15/16 bit) and 
TrueColor(24/32 bit) resolutions.
Control also supports 256 and 16 color modes. 
But in 16 colors mode you cannot use gradient,
and in 256 colors mode control works slower because of 
usage <code>CreateSolidBrush/FillRect</code> 
instead of <code>FillSolidRect</code>. 
<P>If you want rotate text to any angle - define 
<code>PBT_ANY_ANGLE</code> and recompile control</P>
<P>Control is part of UIBits.dll and independent usage requires additional files: <A href="..\drawgdix\index.html">DrawGdiX.h</A>    , MemDC.h

<P>Januar 21, 2001 - version 1.4<BR>
<LI>Gradient Animation and stretching added
<LI>Fixed some bugs from previous version</LI>     

<P>Januar 10, 2001 - version 1.3<BR>
<LI>Code separated to three classes <code>CGradient, CProgress</code> and <code>CProgressCtrlX</code><BR>
<LI>Added tooltips with text formatting
<LI>Added self running snake
<LI>Added palette support for 256 colors mode
<LI>Added shaped style drawing</LI>
<P>September 20, 2000 - version 1.2<BR>
<LI>Added support for "Any angle text rotation"<BR>
  (define <code>PBT_ANY_ANGLE</code> and set font with appropriated angle)
<LI>Added text alignment
<LI>Added possibility to format text (via virtual function <code>FormatText()</code>)<BR>
 e.g. you can show percent as 
  decimal fraction instead of integer
  <LI>Some code improvements</LI>
August 2, 2000 - version 1.1<BR>
<LI>Added multi-color gradient
<LI>Added filling with brush for background and bar (overrides color settings)
<LI>Added borders attribute
<LI>Added vertical text support
<LI>Added snake mode
<LI>Added reverse mode
<LI>Added dual color for text
<LI>Added text formatting 
<LI>Added tied mode for text and rubber bar mode 
<LI>Added support for vertical oriented control 
June 5, 2000 - version 1.0<br>
<A href="">Download demo project - 108 Kb</A><br>
<A href="">Download source - 22 Kb</A>

<P><A href="">Write me about any 
problem or ideas</A>.</P>


By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


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


About the Author

Yury Goltsman
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.

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170118.1 | Last Updated 12 Jun 2002
Article Copyright 2001 by Yury Goltsman
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid