Click here to Skip to main content
15,867,568 members
Articles / Desktop Programming / MFC
Article

CCylinderProgressControlST v1.0

Rate me:
Please Sign up or sign in to vote.
4.97/5 (29 votes)
1 Jul 20033 min read 156.3K   8.4K   95   50
A GDI+ cylinder progress control

Sample Image

SoftechSoftware homepage
SoftechSoftware Email

Abstract

You need GDI+ installed to use this control.

CCylinderProgressControlST is a class derived from MFC CProgressCtrl class. The control has been created as an exercise of converting an existing control written in C# into a new one with the same features written in C++. The conversion was quite simple. You can find the original control here. CCylinderProgressControlST code is more robust than the original one.

CCylinderProgressControlST 
features:

  • Easy to use
  • Standard CProgressCtrl methods
  • Support for negative ranges
  • Support for vertical progress controls
  • Full source code included!
  • Cost-less implementation in existing applications

How to integrate CCylinderProgressControlST in your application

In your project include the following files:

  • CylinderProgressControlST.h
  • CylinderProgressControlST.cpp
With dialog editor create a progress control called, for example, IDC_PROGRESS.

Then create a member variable for this control:
CCylinderProgressControlST m_prgControl;

Now attach the progress control to CCylinderProgressControlST. For dialog-based applications, in your OnInitDialog:

// Call the base-class method
CDialog::OnInitDialog();

// Create the IDC_PROGRESS progress control
m_prgControl.SubclassDlgItem(IDC_PROGRESS, this);

Or in your DoDataExchange:

// Call the base method
CDialog::DoDataExchange(pDX);

// Create the IDC_PROGRESS progress control
DDX_Control(pDX, IDC_PROGRESS, m_prgControl);

Your progress control is now a CCylinderProgressControlST!

Class methods

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]   shLower
//            Specifies the lower limit of the range (default is zero).
//     [IN]   shUpper
//            Specifies the upper limit of the range (default is 100).
//
void SetRange(short shLower, short shUpper)

SetRange32

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 SetRange32(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()

SetColors

Sets the control's colors.

// Parameters:
//     [IN]   cFullColor
//            A GDI+ Color object indicating the color of the currently 
//            displayed bar.
//     [IN]   cEmptyColor
//            A GDI+ Color object indicating the color of the control's 
//            portion currently left empty.
//     [IN]   cOutlineColor
//            A GDI+ Color object indicating the color used to outline the 
//            control.
//     [IN]   cTextColor
//            A GDI+ Color object indicating the color of the displayed text.
//     [IN]   cBkColor
//            A GDI+ Color object indicating the background color of the 
//            control.
//     [IN]   bRepaint
//            If TRUE the control will be repainted.
//
void SetColors(Color cFullColor, Color cEmptyColor, Color cOutlineColor, 
               Color cTextColor, Color cBkColor, BOOL bRepaint = TRUE)

SetFullColor

Sets the color of the currently displayed bar.

// Parameters:
//     [IN]   cColor
//            A GDI+ Color object indicating the color of the currently 
//            displayed bar.
//     [IN]   bRepaint
//            If TRUE the control will be repainted.
//
void SetFullColor(Color cColor, BOOL bRepaint = TRUE)

SetEmptyColor

Sets the color of the control's portion currently left empty.

// Parameters:
//     [IN]   cColor
//            A GDI+ Color object indicating the color of the control's 
//            portion currently left empty.
//     [IN]   bRepaint
//            If TRUE the control will be repainted.
//
void SetEmptyColor(Color cColor, BOOL bRepaint = TRUE)

SetOutlineColor

Sets the color used to outline the control.

// Parameters:
//     [IN]   cColor
//            A GDI+ Color object indicating the color used to outline the 
//            control.
//     [IN]   bRepaint
//            If TRUE the control will be repainted.
//
void SetOutlineColor(Color cColor, BOOL bRepaint = TRUE)

SetTextColor

Sets the color of the displayed text.

// Parameters:
//     [IN]   cColor
//            A GDI+ Color object indicating the color of the displayed text.
//     [IN]   bRepaint
//            If TRUE the control will be repainted.
//
void SetTextColor(Color cColor, BOOL bRepaint = TRUE)

SetBkColor

Sets the background color of the control.

// Parameters:
//     [IN]   cColor
//            A GDI+ Color object indicating the background color of the 
//            control.
//     [IN]   bRepaint
//            If TRUE the control will be repainted.
//
void SetBkColor(Color cColor, BOOL bRepaint = TRUE)

SetShowText

Sets if text must be displayed on the control.

// Parameters:
//     [IN]   bShowText
//            TRUE if text must be displayed on the control.
//     [IN]   bRepaint
//            If TRUE the control will be repainted.
//
void SetShowText(BOOL bShowText, BOOL bRepaint = TRUE)

SetShowOutline

Sets if the control must be outlined.

// Parameters:
//     [IN]   bShowOutline
//            TRUE if the control must be outlined.
//     [IN]   bRepaint
//            If TRUE the control will be repainted.
//
void SetShowOutline(BOOL bShowOutline, BOOL bRepaint = TRUE)

SetAlpha

Sets the alpha component of the colors used to draw the control.

// Parameters:
//     [IN]   byAlpha
//            A BYTE value indicating the alpha component.
//     [IN]   bRepaint
//            If TRUE the control will be repainted.
//
void SetAlpha(BYTE byAlpha, BOOL bRepaint = TRUE)

GetAlpha

Returns the alpha component of the colors used to draw the control.

// Return value:
//     A BYTE indicating the alpha component.
//
BYTE GetAlpha()

SetTooltipText

Sets the text to show in the control tooltip.

// Parameters:
//     [IN]   nId
//            ID number of the string resource containing the text to show.
//     [IN]   bActivate
//            If TRUE the tooltip will be created active.
//
void SetTooltipText(int nId, BOOL bActivate = TRUE)

SetTooltipText

Sets the text to show in the control tooltip.

// Parameters:
//     [IN]   lpszText
//            Pointer to a null-terminated string containing the text to show.
//     [IN]   bActivate
//            If TRUE the tooltip will be created active.
//
void SetTooltipText(LPCTSTR lpszText, BOOL bActivate = TRUE)

ActivateTooltip

Enables or disables the control tooltip.

// Parameters:
//     [IN]   bActivate
//            If TRUE the tooltip will be activated.
//
void ActivateTooltip(BOOL bActivate = TRUE)

DrawTransparent

Enables the transparent mode. Note: this operation is not reversible. DrawTransparent should be called just after the control is created. Do not use trasparent controls until you really need it (you have a bitmapped background) since each transparent control makes a copy in memory of its background. This may bring unnecessary memory use and execution overload.

// Parameters:
//     [IN]   bRepaint
//            If TRUE the control will be repainted.
//
DWORD DrawTransparent(BOOL bRepaint = FALSE)

OnDrawBackground

This function is called every time the control background needs to be painted. If the control is in transparent mode this function will not be called. This is a virtual function that can be rewritten in CCylinderProgressCtrlST-derived classes.

// Parameters:
//     [IN]   pGfx
//            Pointer to a GDI+ Graphics object that indicates the graphic 
//            context.
//     [IN]   rpCtrl
//            Pointer to a GDI+ Rect object that indicates the bounds of the
//            area to be painted.
//
// Return value:
//     CYLINDERPROGRESSCTRLST_OK
//        Function executed successfully.
//
virtual DWORD OnDrawBackground(Graphics* pGfx, Rect* rpCtrl)

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 shows the current bar percentage.

// Parameters:
//     [IN]   pGfx
//            Pointer to a GDI+ Graphics object that indicates the graphic 
//            context.
//     [IN]   nPercentage
//            Current percentage of the progress bar.
//     [IN]   rpCtrl
//            Pointer to a GDI+ Rect object that indicates the dimensions of 
//            the entire control.
//     [IN]   rpEmpty
//            Pointer to a GDI+ Rect object that indicates the dimensions of 
//            the control's
//            portion currently left empty.
//     [IN]   rpFull
//            Pointer to a GDI+ Rect object that indicates the dimensions of 
//            the currently displayed bar.
//     [IN]   bHorizontal
//            TRUE if the progress is horizontal, otherwise FALSE.
//
// Return value:
//     CYLINDERPROGRESSCTRLST_OK
//        Function executed successfully.
//
virtual DWORD OnDrawText(Graphics* pGfx, int nPercentage, Rect* rpCtrl, 
//                       Rect* rpEmpty, Rect* rpFull, BOOL bHorizontal)

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.0 (27/June/2003)
    First release

Disclaimer

THE SOFTWARE AND THE ACCOMPANYING FILES ARE DISTRIBUTED "AS IS" AND WITHOUT ANY WARRANTIES WHETHER EXPRESSED OR IMPLIED. NO RESPONSIBILITIES 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

 
GeneralWCHAR Error still not fixed Pin
merano4-Jun-10 6:11
merano4-Jun-10 6:11 
QuestionCan not work in child window.... Pin
shaino16-Oct-07 16:26
shaino16-Oct-07 16:26 
QuestionCan I use it in SDI VIEW Pin
chen.zd14-Jun-07 2:53
chen.zd14-Jun-07 2:53 
AnswerRe: Can I use it in SDI VIEW Pin
chen.zd14-Jun-07 3:05
chen.zd14-Jun-07 3:05 
GeneralGood - as always Pin
eli150219794-Aug-05 22:01
eli150219794-Aug-05 22:01 
GeneralRe: Good - as always Pin
Davide Calabro2-May-06 4:09
Davide Calabro2-May-06 4:09 
Generalproblem with progress text Pin
bachi24-Jan-05 19:50
bachi24-Jan-05 19:50 
Generalrelease build Pin
bachi24-Jan-05 19:48
bachi24-Jan-05 19:48 
Generaltext visible problem Pin
Eunwook Lee1-Nov-04 20:52
Eunwook Lee1-Nov-04 20:52 
GeneralCylinderProgressCtrlST not visible! Pin
Vincelastar21-Dec-03 6:43
Vincelastar21-Dec-03 6:43 
GeneralRe: CylinderProgressCtrlST not visible! Pin
Gizz_0113-May-04 5:21
Gizz_0113-May-04 5:21 
Generalwhy Pin
xuchuangeng3-Aug-03 16:26
xuchuangeng3-Aug-03 16:26 
GeneralRe: why Pin
Davide Calabro3-Aug-03 23:22
Davide Calabro3-Aug-03 23:22 
GeneralJust beautiful! Pin
Jason Troitsky (was Hattingh)22-Jul-03 3:38
Jason Troitsky (was Hattingh)22-Jul-03 3:38 
GeneralRe: Just beautiful! Pin
Davide Calabro22-Jul-03 5:45
Davide Calabro22-Jul-03 5:45 
GeneralUnicode problem Pin
jikanyanwin323-Jul-03 23:26
jikanyanwin323-Jul-03 23:26 
GeneralRe: Unicode problem Pin
PixiGreg8-Jul-03 3:59
PixiGreg8-Jul-03 3:59 
GeneralRe: Unicode problem Pin
jikanyanwin329-Jul-03 18:56
jikanyanwin329-Jul-03 18:56 
General!! Pin
Ravi Bhavnani3-Jul-03 3:16
professionalRavi Bhavnani3-Jul-03 3:16 
GeneralRe: !! Pin
Davide Calabro3-Jul-03 6:32
Davide Calabro3-Jul-03 6:32 
QuestionWhat about non-unicode builds ? Pin
PixiGreg2-Jul-03 21:07
PixiGreg2-Jul-03 21:07 
AnswerRe: What about non-unicode builds ? Pin
Davide Calabro2-Jul-03 22:17
Davide Calabro2-Jul-03 22:17 
GeneralRe: What about non-unicode builds ? Pin
PixiGreg3-Jul-03 1:59
PixiGreg3-Jul-03 1:59 
GeneralRe: What about non-unicode builds ? Pin
David A. Robinson8-Jul-03 1:51
David A. Robinson8-Jul-03 1:51 
GeneralRe: What about non-unicode builds ? Pin
PixiGreg8-Jul-03 3:55
PixiGreg8-Jul-03 3: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.