CCylinderProgressControlST v1.0






4.97/5 (25 votes)
Jul 2, 2003
3 min read

159978

8400
A GDI+ cylinder progress control
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
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.