|
|
Title |
A Progress bar with bitmap fill
|
Summary |
With this class your applications can have progress bars using bitmaps as seen in many modern installation programs and games |
Contributor |
Davide Calabro
|
Published |
28-Aug-2002 |
Last updated |
28-Aug-2002 |
|
|
SoftechSoftware homepage
SoftechSoftware Email
Abstract
CProgressCtrlST is a class derived from MFC CProgressCtrl class. With this class your applications can have progress bars using bitmaps as seen in many modern installation programs and games!
CProgressCtrlST features:
- Easy to use
- Standard CProgressCtrl methods
- Support for 256+ colors bitmaps
- Support for negative ranges
- Support for vertical progress controls
- Full source code included!
- Cost-less implementation in existing applications
How to integrate CProgressCtrlST in your application
In your project include the following files:
- ProgressCtrlST.h
- ProgressCtrlST.cpp
You also need a bitmap that will be used to draw the progress bar. For example include in your project Tile.bmp and call it IDB_TILE. With dialog editor create a progress control called, for example, IDC_TILED.
Then create a member variable for this progress control:
CProgressCtrlST m_progressTiled;
Now attach the progress control to CProgressCtrlST. For dialog-based applications, in your OnInitDialog:
// Call the base-class method
CDialog::OnInitDialog();
// Create the IDC_TILED progress control
m_progressTiled.SubclassDlgItem(IDC_TILED, this);
Or in your DoDataExchange:
// Call the base method
CDialog::DoDataExchange(pDX);
// Create the IDC_TILED progress control
DDX_Control(pDX, IDC_TILED, m_progressTiled);
The control will have the same default range and start position as in the base MFC class CProgressCtrl. These values can be modified using the same methods of the base class such as, for example, SetRange or SetPos . At this moment OffsetPos is not supported.
By default the control will draw itself just like a normal progress bar. A bitmap can be assigned to get a progress bar showing it instead of normal standard blocks!
This bitmap will be tiled to paint the necessary portion of the progress bar; it will not be shrinked or enlarged in any manner.
Assign a bitmap to the progress bar:
// Assign a bitmap
m_progressTiled.SetBitmap(IDB_TILE);
Your progress control is now a CProgressCtrlST!
Class methods
SetBitmap
Sets the bitmap to use to draw the progress bar.
// Parameters:
// [IN] nBitmap
// Resource ID of the bitmap to use as background.
// Pass NULL to remove any previous bitmap.
// [IN] bRepaint
// If TRUE the control will be repainted.
//
// Return value:
// PROGRESSST_OK
// Function executed successfully.
// PROGRESSST_INVALIDRESOURCE
// The resource specified cannot be found or loaded.
//
DWORD SetBitmap(int nBitmap, BOOL bRepaint = TRUE)
SetBitmap
Sets the bitmap to use to draw the progress bar.
// Parameters:
// [IN] hBitmap
// Handle to the bitmap to use as background.
// Pass NULL to remove any previous bitmap.
// [IN] bRepaint
// If TRUE the control will be repainted.
//
// Return value:
// PROGRESSST_OK
// Function executed successfully.
// PROGRESSST_INVALIDRESOURCE
// The resource specified cannot be found or loaded.
//
DWORD SetBitmap(HBITMAP hBitmap, BOOL bRepaint = TRUE)
SetRange
Sets the upper and lower limits of the progress bar control's range
and redraws the bar to reflect the new ranges.
// Parameters:
// [IN] nLower
// Specifies the lower limit of the range (default is zero).
// [IN] nUpper
// Specifies the upper limit of the range (default is 100).
//
void SetRange(int nLower, int nUpper)
SetStep
Specifies the step increment for a progress bar control.
The step increment is the amount by which a call to StepIt increases
the progress bar's current position.
// Parameters:
// [IN] nStep
// New step increment.
//
// Return value:
// The previous step increment.
//
int SetStep(int nStep)
SetPos
Sets the progress bar control's current position as specified by nPos
and redraws the bar to reflect the new position.
The position of the progress bar control is not the physical location on the screen,
but rather is between the upper and lower range indicated in SetRange.
// Parameters:
// [IN] nPos
// New position of the progress bar control.
//
// Return value:
// The previous position of the progress bar control.
//
int SetPos(int nPos)
StepIt
Advances the current position for a progress bar control by the step increment
and redraws the bar to reflect the new position.
The step increment is set by the SetStep method.
// Return value:
// The previous position of the progress bar control.
//
int StepIt()
OnDrawText
This function is called each time the progress bar is redrawn.
It is a virtual function to let derived classes do custom drawing.
The default implementation does nothing.
// Parameters:
// [IN] pDC
// Pointer to the device context.
// [IN] nPercentage
// Current percentage of the progress bar.
// [IN] rcCtrl
// A CRect object that indicates the dimensions of the
// entire control.
// [IN] rcProgress
// A CRect object that indicates the dimensions of the
// currently displayed bar.
// [IN] bVertical
// TRUE if the progress is vertical, otherwise FALSE.
//
virtual void OnDrawText(CDC* pDC, int nPercentage, CRect rcCtrl,
CRect rcProgress, BOOL bVertical)
GetVersionI
Returns the class version as a short value.
// Return value:
// Class version. Divide by 10 to get actual version.
//
static short GetVersionI()
GetVersionC
Returns the class version as a string value.
// Return value:
// Pointer to a null-terminated string containig the class version.
//
static LPCTSTR GetVersionC()
History
- v1.1 (27/August/2002)
Class name changed to CProgressCtrlST
Added support for vertical progress controls
- v1.0 (01/January/1999)
First release
Disclaimer
THE SOFTWARE AND THE ACCOMPANYING FILES ARE DISTRIBUTED "AS IS" AND WITHOUT ANY WARRANTIES WHETHER EXPRESSED OR IMPLIED.
NO REPONSIBILITIES FOR POSSIBLE DAMAGES OR EVEN FUNCTIONALITY CAN BE TAKEN.
THE USER MUST ASSUME THE ENTIRE RISK OF USING THIS SOFTWARE.
Terms of use
THIS SOFTWARE IS FREE FOR PERSONAL USE OR FREEWARE APPLICATIONS.
IF YOU USE THIS SOFTWARE IN COMMERCIAL OR SHAREWARE APPLICATIONS YOU
ARE GENTLY ASKED TO DONATE 5$ (FIVE U.S. DOLLARS) TO THE AUTHOR:
Davide Calabro'
P.O. Box 65
21019 Somma Lombardo (VA)
Italy
|