|
<HTML>
<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>
<META
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"
name=Keywords>
<META content="Copyright � 1999-2000 Yury Goltsman, All Rights Reserved." name=Copyright>
<BODY>
<LINK
href="..\global\global.css"
type=text/css rel=stylesheet>
<h3 align="center"><font color="#a0a099">
Enhanced ProgressBar Control v1.4
</font></h3>
<hr>
<p><IMG alt="Sample Image" src="progressctrlx.gif" ></p>
<p><u>Environment:</u> VC6, NT4/9x</p>
<p>
<H2>Introduction</H2>
<p>In this article I want to introduce enhanced ProgressBar control.
I collect some ideas from article
on <a href="http://www.codeguru.com">CodeGuru</a>
and <a href="http://www.codeproject.com">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>
-> <code>CProgress</code> -> <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>.
</p>
<H2>Features:</H2>
<P><UL>
<LI>Filling with gradient colors
<LI>Multi-color gradient (unlimited number of colors)
<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>Borders
<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
<LI>...........</LI>
</UL>
<P></P>
<H2>Advanced Interface:</H2>
<P>
Text Alignment (to set text alignment styles use "SetTextAlign")
<pre>
#define PBS_LEFT 0x0010L
#define PBS_RIGHT 0x0020L
#define PBS_CENTER 0x0030L
#define PBS_TOP 0x0040L
#define PBS_BOTTOM 0x0080L
#define PBS_VCENTER 0x00C0L
</pre>
<P>
Text Format (to set text format use "SetTextFormat" and "HideText"):
<pre>
#define PBS_SHOW_PERCENT 0x0100
#define PBS_SHOW_POSITION 0x0200
#define PBS_SHOW_TEXTONLY 0x0300
</pre>
<P>
Control Styles (use "ModifyBarStyle" or appropriated functions):
<pre>
#define PBS_TIED_TEXT 0x1000
#define PBS_RUBBER_BAR 0x2000
#define PBS_REVERSE 0x4000
#define PBS_SNAKE 0x8000
</pre>
<p>Advanced functionality:
<pre >
CGradient:
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();
</pre>
<pre>
CProgress:
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();
</pre>
<pre>
CProgressCtrlX:
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();
</pre>
<P>
You can use:
<UL>
<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>
</UL>
<P>See Test Project for additional information of usage.
<H2>Notes</H2>
<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
<h3>History</h3>
<P>Januar 21, 2001 - version 1.4<BR>
<UL>
<LI>Gradient Animation and stretching added
<LI>Fixed some bugs from previous version</LI>
</UL>
<P>Januar 10, 2001 - version 1.3<BR>
<UL>
<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>
</UL>
<P>September 20, 2000 - version 1.2<BR>
<UL>
<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>
</UL>
August 2, 2000 - version 1.1<BR>
<UL>
<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
(<code>PBS_VERTICAL</code>)</LI>
</UL>
June 5, 2000 - version 1.0<br>
<P></P>
<P>
<h3>Downloads</h3>
<A href="progressctrlx_demo.zip">Download demo project - 108 Kb</A><br>
<A href="progressctrlx_src.zip">Download source - 22 Kb</A>
<P><A href="mailto:ygprg@go.to?Subject=ProgressCtrlX">Write me about any
problem or ideas</A>.</P>
</BODY></HTML>
|
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.
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.