Introduction
Always wondered how to make the old-school style progress bars that had different colors and the percentage changed colors when the progress reached it? Here you go, and it's fully customizable! You also use a floating point number in order to set the percentage (although it's programmed to not show the decimal when drawing). This lets it do a lot of the calculating for you.
Background
I've been using this one I created (over a decade ago) and noticed that no one has ever posted anything like this. This is compatible of course with any Windows operating system. It was originally compiled in with Visual C++ 6.0 but should work with any Visual Studio Environment.
Using the Code
Class Documentation
See header file for the most up to date class documentation. Most of the parameters are self explanatory, otherwise a comment is placed beside it to help.
CProgressBar
BOOL Create( DWORD dwExStyle,
DWORD dwStyle,
const RECT& rect,
CWnd *pParentWnd,
COLORREF crBarColor = 0xFF, COLORREF crBkColor = 0xFFFFFF, COLORREF crTextOverColor = 0xFFFFFF, COLORREF crTextOutColor = 0, BOOL bShowPercentage = 1,
CFont *pFont = NULL );
float GetStepAmount( ) const;
void Step();
void SetStepAmount( float fStepAmount );
void SetPosition( float fPos );
float GetPosition( ) const;
void SetRange( UINT nStartPos, UINT nEndPos );
Messages Implemented
PBM_STEPIT
PBM_SETRANGE32
PBM_GETPOS
PBM_FLOAT_SETPOS PBM_FLOAT_SETSTEP
To use, simply use it like you would any other window. Create a CProgressBar
object in your window's class and call the CProgressBar::Create()
member function in your window initialization. Example:
m_wndBar.Create(WS_EX_CLIENTEDGE, WS_BORDER |
WS_VISIBLE | WS_CHILD, rc, this, RGB(0, 100, 255), 0xFFFFFF, 0xFFFFFF);
Now you can start using the action functions such as SetPosition
, SetRange
, Step()
, etc... Have fun. You are welcome.
History
- v1.1 - 1/1/2015: Added float compatible message handlers
- v1.0 - 1/1/2004: Initial release