Click here to Skip to main content
15,884,976 members
Articles / Desktop Programming / MFC
Article

CProgressCtrlST 1.1

Rate me:
Please Sign up or sign in to vote.
4.38/5 (10 votes)
3 Sep 20023 min read 105.5K   5.8K   48   8
A bitmapped progress bar control

Sample Image

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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Italy Italy
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMemory Leak.. Pin
hunny7119-Oct-06 22:24
hunny7119-Oct-06 22:24 
QuestionPROBLEM WITH USING IN STATIC Pin
MacGadger20-May-06 20:17
MacGadger20-May-06 20:17 
QuestionHow to Remove tht BORDER ???? Pin
MacGadger22-Apr-06 21:51
MacGadger22-Apr-06 21:51 
GeneralSmall bugfix to avoid big troubles ;-) Pin
Chervinsky Olexander23-Dec-04 1:04
Chervinsky Olexander23-Dec-04 1:04 
Hi, all

It would not harm, if you remove the huge leak of GDI-resources Smile | :)

Add the following 3 lines to the end of method 'CProgressCtrlST::OnPaint()' :

void CProgressCtrlST::OnPaint() :
{
...

::DeleteObject( hbmpTemp );
::DeleteObject( hdcMem );
::DeleteObject( hdcTemp );
}

Best regards, Sashko
GeneralRe: Small bugfix to avoid big troubles ;-) Pin
QuiJohn19-May-06 5:14
QuiJohn19-May-06 5:14 
Questionhow to set a background bmp? Pin
cbir13-Mar-04 4:09
cbir13-Mar-04 4:09 
GeneralSetRange Pin
greba19-Mar-03 9:29
greba19-Mar-03 9:29 
GeneralRe: SetRange Pin
Davide Calabro19-Mar-03 20:55
Davide Calabro19-Mar-03 20:55 

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.