Click here to Skip to main content
Click here to Skip to main content

CCylinderProgressControlST v1.0

, 1 Jul 2003
Rate this:
Please Sign up or sign in to vote.
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

About the Author

Davide Calabro
Web Developer
Italy Italy
No Biography provided

Comments and Discussions

 
GeneralWCHAR Error still not fixed Pinmembermerano4-Jun-10 6:11 
QuestionCan not work in child window.... Pinmembershaino16-Oct-07 16:26 
QuestionCan I use it in SDI VIEW Pinmemberchen_zd14-Jun-07 2:53 
AnswerRe: Can I use it in SDI VIEW Pinmemberchen_zd14-Jun-07 3:05 
GeneralGood - as always Pinmembereli150219794-Aug-05 22:01 
GeneralRe: Good - as always PinmemberDavide Calabro2-May-06 4:09 
Generalproblem with progress text Pinmemberbachi24-Jan-05 19:50 
Generalrelease build Pinmemberbachi24-Jan-05 19:48 
Generaltext visible problem PinmemberEunwook Lee1-Nov-04 20:52 
GeneralCylinderProgressCtrlST not visible! PinmemberVincelastar21-Dec-03 6:43 
GeneralRe: CylinderProgressCtrlST not visible! PinmemberGizz_0113-May-04 5:21 
Generalwhy Pinmemberxuchuangeng3-Aug-03 16:26 
GeneralRe: why PinmemberDavide Calabro3-Aug-03 23:22 
what is an "Exec error" Confused | :confused:
 
SoftechSoftware
Davide Calabro'
davide_calabro@yahoo.com
http://www.softechsoftware.it
GeneralJust beautiful! PinmemberJ.G. Hattingh22-Jul-03 3:38 
GeneralRe: Just beautiful! PinmemberDavide Calabro22-Jul-03 5:45 
GeneralUnicode problem Pinmemberjikanyanwin323-Jul-03 23:26 
GeneralRe: Unicode problem PinmemberPixiGreg8-Jul-03 3:59 
GeneralRe: Unicode problem Pinmemberjikanyanwin329-Jul-03 18:56 
General!! PinmemberRavi Bhavnani3-Jul-03 3:16 
GeneralRe: !! PinmemberDavide Calabro3-Jul-03 6:32 
QuestionWhat about non-unicode builds ? PinmemberPixiGreg2-Jul-03 21:07 
AnswerRe: What about non-unicode builds ? PinmemberDavide Calabro2-Jul-03 22:17 
GeneralRe: What about non-unicode builds ? PinmemberPixiGreg3-Jul-03 1:59 
GeneralRe: What about non-unicode builds ? PinmemberDavid A. Robinson8-Jul-03 1:51 
GeneralRe: What about non-unicode builds ? PinmemberPixiGreg8-Jul-03 3:55 
GeneralRe: What about non-unicode builds ? PinmemberDavide Calabro8-Jul-03 4:16 
GeneralRe: What about non-unicode builds ? PinmemberDavid A. Robinson8-Jul-03 7:30 
GeneralRe: What about non-unicode builds ? PinmemberOrkblutt11-Jul-03 1:27 
GeneralRe: What about non-unicode builds ? PinmemberPixiGreg11-Jul-03 5:41 
GeneralRe: What about non-unicode builds ? PinmemberOrkblutt11-Jul-03 18:20 
GeneralRe: What about non-unicode builds ? PinmemberPixiGreg11-Jul-03 23:03 
GeneralRe: What about non-unicode builds ? PinmemberOrkblutt12-Jul-03 0:16 
GeneralRe: What about non-unicode builds ? PinmemberPixiGreg12-Jul-03 9:26 
GeneralRe: What about non-unicode builds ? PinmemberOrkblutt12-Jul-03 12:24 
GeneralRe: What about non-unicode builds ? PinmemberDavide Calabro13-Jul-03 2:06 
GeneralRe: What about non-unicode builds ? PinmemberOrkblutt13-Jul-03 2:29 
GeneralRe: What about non-unicode builds ? PinmemberDadhi oznobishin@yahoo.com15-Mar-05 3:09 
GeneralRe: What about non-unicode builds ? PinmemberMike Kondratyuk14-Aug-06 13:43 
Generalthe code above is not correct,fixed here! PinmemberEversoft13-Apr-09 17:35 
GeneralGot 2 compile errors. PinmemberWREY2-Jul-03 17:42 
GeneralRe: Got 2 compile errors. PinmemberDavide Calabro2-Jul-03 22:15 
GeneralIt's working now ! PinmemberWREY3-Jul-03 7:18 
GeneralRe: It's working now ! PinmemberPixiGreg8-Jul-03 4:03 
QuestionWhy no interaction like a slider control? PinmemberJohn A. Johnson2-Jul-03 10:50 
AnswerRe: Why no interaction like a slider control? PinmemberDavide Calabro2-Jul-03 22:15 
GeneralRe: Why no interaction like a slider control? PinmemberJohn A. Johnson2-Jul-03 22:20 
AnswerRe: Why no interaction like a slider control? PinmemberCarlos H. Perez2-Jul-03 22:25 
GeneralRe: Why no interaction like a slider control? PinmemberJohn A. Johnson3-Jul-03 0:28 
GeneralRe: Why no interaction like a slider control? PinmemberDavide Calabro3-Jul-03 6:41 
AnswerRe: Why no interaction like a slider control? Pinmemberarmentage13-Jun-05 6:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web02 | 2.8.140709.1 | Last Updated 2 Jul 2003
Article Copyright 2003 by Davide Calabro
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid