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

CCylinderProgressControlST v1.0

By , 1 Jul 2003
 

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
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralWCHAR Error still not fixedmembermerano4 Jun '10 - 6:11 
The WCHAR Error is still not fixed.
 
I think the CA2W depends on
 
class CA2WEX
 
When you do not like that does work allways:
 
// alloc and copy
WCHAR *lfFaceName = (WCHAR *)malloc(LF_FACESIZE * sizeof(WCHAR));
for(int i=0; i<LF_FACESIZE; i++) lfFaceName[i] = (WCHAR)csLogFont.lfFaceName[i];
 
			Font f( (WCHAR *)lfFaceName, emSize, FontStyleRegular, UnitPoint, NULL);
 
if(lfFaceName) free(lfFaceName);

QuestionCan not work in child window....membershaino16 Oct '07 - 16:26 
Cry | :((
 
Frist,the code need to use:
------------------------------------------
#include "gdiplus.h"
#pragma comment(lib, "gdiplus.lib")
 
// GDI+ namespace
using namespace Gdiplus;
------------------------------------------
in my stdafx.h file.
 
then,some problem in the SubclassDlgItem() when the parent windows is ChildWindow...
 

QuestionCan I use it in SDI VIEWmemberchen_zd14 Jun '07 - 2:53 
when I Create it in InitrialUpdate() in a SDI view application, the progrom always collapse on starting. can it be used this way? thank you
 
chenzd

AnswerRe: Can I use it in SDI VIEWmemberchen_zd14 Jun '07 - 3:05 
Sorry , my own fault, not initialize GDIPlus
 
chenzd

GeneralGood - as alwaysmembereli150219794 Aug '05 - 22:01 
I must say the each one of your controls is better then
the other.
Keep giving us the good stuff.
 
Best,
Eli
GeneralRe: Good - as alwaysmemberDavide Calabro2 May '06 - 4:09 
Some months later.... I say you thanks very much!
 
Smile | :)
 
SoftechSoftware
Davide Calabro'
davide_calabro@yahoo.com
http://www.softechsoftware.it
Generalproblem with progress textmemberbachi24 Jan '05 - 19:50 
hello everyone.
 
when we build the tool in release mode.. the text is not getting displayed.
i have used PixiGreg's code but this is not giving the result for the release version.
 
all in all.. Its a wonderful and sexy tool.
please help me out on this one.


Generalrelease buildmemberbachi24 Jan '05 - 19:48 
hello everyone.
 
when we build the tool in release mode.. the text is not getting displayed.
i have used PixiGreg's code but this is not giving the result for the release version.
 
all in all.. Its a wonderful and sexy tool.Smile | :)
please help me out on this one.

Generaltext visible problemmemberEunwook Lee1 Nov '04 - 20:52 
Hi Davide~
I found one problem.
Control's parent is not dialog window(just parent is another control window), text is not visible...
I don't know why...
Could you please help me?
Thanks!

GeneralCylinderProgressCtrlST not visible!memberVincelastar21 Dec '03 - 6:43 
First of all thank you for all your work. This control looks very nice but I have a strange problem. I have installed GDI+ ,and I think that it has been done succesfully because your demo works.(I can execute it correctly)
But when I use your class in my project, everything seems working (compiling and linking succesfull), but at run time the CylinderProgressCtrlST is just not displayed, invisible. Even stranger when I put my mouse over the place where I have put the Progress bar, the toolTipText is displayed!
(Another strange thing is that when I put not 'm_progress.SetShowText(FALSE,FALSE)' a fatal error occurs at runtime)...
Could you please help me?
Thanks!
GeneralRe: CylinderProgressCtrlST not visible!memberGizz_0113 May '04 - 5:21 
GDI+ is not initialized.
 
Check the example. In CGenericMFCApp::InitInstance() there's a line showing how you can do it:

// Initialize GDI+
m_GDIpInitializer.Initialize();

 
Gizz
Generalwhymemberxuchuangeng3 Aug '03 - 16:26 
sf.SetAlignment(StringAlignmentCenter);
 
Exec error,whyConfused | :confused:
GeneralRe: whymemberDavide 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!memberJ.G. Hattingh22 Jul '03 - 3:38 
I love it! You can tell how professional I am: I'm trying to think of an app to write just so i can use your control!
GeneralRe: Just beautiful!memberDavide Calabro22 Jul '03 - 5:45 
Big Grin | :-D
 
SoftechSoftware
Davide Calabro'
davide_calabro@yahoo.com
http://www.softechsoftware.it
GeneralUnicode problemmemberjikanyanwin323 Jul '03 - 23:26 
It seems that this progress bar can only work under UNICODE condition.
Can it work under the ASCII mode?
GeneralRe: Unicode problemmemberPixiGreg8 Jul '03 - 3:59 
have a look at my post below Wink | ;)
 
pixigreg
GeneralRe: Unicode problemmemberjikanyanwin329 Jul '03 - 18:56 
Thank you!Smile | :) Smile | :)
General!!memberRavi Bhavnani3 Jul '03 - 3:16 
Davide, you got my 5 - as usual! Smile | :)
 
/ravi
 
Let's put "civil" back in "civilization"
Home | Articles | Freeware | Music
ravib@ravib.com

GeneralRe: !!memberDavide Calabro3 Jul '03 - 6:32 
Thank you! Big Grin | :-D
 
SoftechSoftware
Davide Calabro'
davide_calabro@yahoo.com
http://www.softechsoftware.it
QuestionWhat about non-unicode builds ?memberPixiGreg2 Jul '03 - 21:07 
Great control !
 
However, this doesn't compile with non-unicode builds.
This could be repaired by putting two A2W() in case of non-unicode.
 
bye.
 
p i x i g r e g
AnswerRe: What about non-unicode builds ?memberDavide Calabro2 Jul '03 - 22:17 
GDI+ only supports Unicode. Yes, you can do convertions in any way you like, such as for example A2W() or simply removing the code that performs font operations and do it yourself directly into the main application.
 
SoftechSoftware
Davide Calabro'
davide_calabro@yahoo.com
http://www.softechsoftware.it
GeneralRe: What about non-unicode builds ?memberPixiGreg3 Jul '03 - 1:59 
Davide Calabro wrote:
GDI+ only supports Unicode
 
Indeed, you can have non-unicode builds and pass unicode strings to it.
So you don't want to implement these conversion macro directly so guys using your code wouldn't have to bother adding themselves the conversion macro ? Frown | :(
That would have made your control perfect...
 
p i x i g r e g
GeneralRe: What about non-unicode builds ?memberDavid A. Robinson8 Jul '03 - 1:51 
Where do you add the A2W calls in the code.
I'd like to try it.

 
David
GeneralRe: What about non-unicode builds ?memberPixiGreg8 Jul '03 - 3:55 
I've submitted the modified code that follows to the author, but seemingly he doesn't care about Confused | :confused:
 
Just replace the same function in the .cpp file of the control :
 
DWORD CCylinderProgressCtrlST::OnDrawText(Graphics* pGfx, int nPercentage, Rect* rpCtrl, Rect* rpEmpty, Rect* rpFull, BOOL bHorizontal)
{
	if (m_bShowText)
	{
		CFont*	pFont = NULL;
 
		pFont = GetParent()->GetFont();
		if (pFont)
		{
			TCHAR			szText[256];
			LOGFONT			csLogFont;
			StringFormat	sf;
			REAL			emSize = 0;
			SolidBrush		brText(m_cTextColor);
			RectF			rCtrl((REAL)rpCtrl->X, (REAL)rpCtrl->Y, (REAL)rpCtrl->Width, (REAL)rpCtrl->Height);
 
			pFont->GetLogFont(&csLogFont);
 
			emSize = (REAL)-MulDiv(csLogFont.lfHeight, 72, (int)pGfx->GetDpiY());
 
#ifdef _UNICODE
			Font f(csLogFont.lfFaceName, emSize, FontStyleRegular, UnitPoint, NULL);
#else
#if _ATL_VER >= 0x0700
			CA2W lpszwFont((LPCSTR)csLogFont.lfFaceName);
			Font f(lpszwFont, emSize, FontStyleRegular, UnitPoint, NULL);
#else
			USES_CONVERSION;
			Font f(A2W((LPCSTR)csLogFont.lfFaceName),
				emSize, FontStyleRegular, UnitPoint, NULL);
#endif
#endif
			sf.SetAlignment(StringAlignmentCenter);
			sf.SetLineAlignment(StringAlignmentCenter);
 
			_stprintf(szText, _T("%d%%"), nPercentage);
			pGfx->SetTextRenderingHint(TextRenderingHintAntiAlias);
 
#ifdef _UNICODE
			pGfx->DrawString(szText, -1, &f, rCtrl, &sf, &brText);
#else
#if _ATL_VER >= 0x0700
			CA2W lpszwText((LPCSTR)szText);
			pGfx->DrawString(lpszwText, -1, &f, rCtrl, &sf, &brText);
#else
			Font f(A2W((LPCSTR)szText),
				emSize, FontStyleRegular, UnitPoint, NULL);
#endif		
#endif
 
		} // if
	} // if

	return CYLINDERPROGRESSCTRLST_OK;
} // End of OnDrawText

 
pixigreg
GeneralRe: What about non-unicode builds ?memberDavide Calabro8 Jul '03 - 4:16 
PixiGreg wrote:
I've submitted the modified code that follows to the author, but seemingly he doesn't care about
 
People sometimes is busy....
 
SoftechSoftware
Davide Calabro'
davide_calabro@yahoo.com
http://www.softechsoftware.it
GeneralRe: What about non-unicode builds ?memberDavid A. Robinson8 Jul '03 - 7:30 
Interesting, I've never had to do it that way, great to learn something new!
 
Probably should have thought about CA2W as a Cast.

 
David
GeneralRe: What about non-unicode builds ?memberOrkblutt11 Jul '03 - 1:27 
Hi,
 
have problem with this line...
 
Font f(A2W((LPCSTR)csLogFont.lfFaceName),emSize, FontStyleRegular, UnitPoint, NULL);
 
=> A2W undeclared identifier... what's that ???
thanks...
 
else your CCylinderProgressCtrlST runs really well Davide!!! ... have make a beautiful GUI with it!! ( RSAttack576 client GUI)
thanks Smile | :)
GeneralRe: What about non-unicode builds ?memberPixiGreg11 Jul '03 - 5:41 
Orkblutt wrote:
=> A2W undeclared identifier... what's that ???
thanks...

 
#include <ATLCONV.H>
 
bye!
 
p i x i g r e g
GeneralRe: What about non-unicode builds ?memberOrkblutt11 Jul '03 - 18:20 
thanks pixigreg!
 
have now problem with this line
 
Font f(A2W((LPCSTR)szText),emSize, FontStyleRegular, UnitPoint, NULL);
 
=> f redefinition Frown | :(
 
i'm trying that:
 
DWORD CCylinderProgressCtrlST::OnDrawText(Graphics* pGfx, int nPercentage, Rect* rpCtrl, Rect* rpEmpty, Rect* rpFull, BOOL bHorizontal)
{
if (m_bShowText)
{
CFont* pFont = NULL;
 
pFont = GetParent()->GetFont();
if (pFont)
{
TCHAR szText[256];
LOGFONT csLogFont;
StringFormat sf;
REAL emSize = 0;
SolidBrush brText(m_cTextColor);
RectF rCtrl((REAL)rpCtrl->X, (REAL)rpCtrl->Y, (REAL)rpCtrl->Width, (REAL)rpCtrl->Height);
 
pFont->GetLogFont(&csLogFont);
 
emSize = (REAL)-MulDiv(csLogFont.lfHeight, 72, (int)pGfx->GetDpiY());
 
USES_CONVERSION;
LPWSTR x = A2W((LPCSTR)csLogFont.lfFaceName);
 
Font f(x,emSize, FontStyleRegular, UnitPoint, NULL);
sf.SetAlignment(StringAlignmentCenter);
sf.SetLineAlignment(StringAlignmentCenter);
_stprintf(szText, _T("%d%%"), nPercentage);
pGfx->SetTextRenderingHint(TextRenderingHintAntiAlias);
x=A2W((LPCSTR)szText);
Font z(x,emSize, FontStyleRegular, UnitPoint, NULL);
} // if
} // if
 
return CYLINDERPROGRESSCTRLST_OK;
} // End of OnDrawText
 

no error but no "x%" in my progress bar :(
GeneralRe: What about non-unicode builds ?memberPixiGreg11 Jul '03 - 23:03 
oops, my mistake...
 
copy & paste is sometimes not very tricky Smile | :)
 
DWORD CCylinderProgressCtrlST::OnDrawText(Graphics* pGfx, int nPercentage, Rect* rpCtrl, Rect* rpEmpty, Rect* rpFull, BOOL bHorizontal)
{
	if (m_bShowText)
	{
		CFont*	pFont = NULL;
 
		pFont = GetParent()->GetFont();
		if (pFont)
		{
			TCHAR			szText[256];
			LOGFONT			csLogFont;
			StringFormat	sf;
			REAL			emSize = 0;
			SolidBrush		brText(m_cTextColor);
			RectF			rCtrl((REAL)rpCtrl->X, (REAL)rpCtrl->Y, (REAL)rpCtrl->Width, (REAL)rpCtrl->Height);
 
			pFont->GetLogFont(&csLogFont);
 
			emSize = (REAL)-MulDiv(csLogFont.lfHeight, 72, (int)pGfx->GetDpiY());
 
#ifdef _UNICODE
			Font f(csLogFont.lfFaceName, emSize, FontStyleRegular, UnitPoint, NULL);
#else
#if _ATL_VER >= 0x0700
			CA2W lpszwFont((LPCSTR)csLogFont.lfFaceName);
			Font f(lpszwFont, emSize, FontStyleRegular, UnitPoint, NULL);
#else
			USES_CONVERSION;
			Font f(A2W((LPCSTR)csLogFont.lfFaceName),
				emSize, FontStyleRegular, UnitPoint, NULL);
#endif
#endif
			sf.SetAlignment(StringAlignmentCenter);
			sf.SetLineAlignment(StringAlignmentCenter);
 
			_stprintf(szText, _T("%d%%"), nPercentage);
			pGfx->SetTextRenderingHint(TextRenderingHintAntiAlias);
 
#ifdef _UNICODE
			pGfx->DrawString(szText, -1, &f, rCtrl, &sf, &brText);
#else
#if _ATL_VER >= 0x0700
			CA2W lpszwText((LPCSTR)szText);
			pGfx->DrawString(lpszwText, -1, &f, rCtrl, &sf, &brText);
#else
			pGfx->DrawString(A2W((LPCSTR)szText), -1, &f, rCtrl, &sf, &brText);
#endif		
#endif
 
		} // if
	} // if

	return CYLINDERPROGRESSCTRLST_OK;
} // End of OnDrawText

 
p i x i g r e g
GeneralRe: What about non-unicode builds ?memberOrkblutt12 Jul '03 - 0:16 
many thanks pixigreg!! run very well now Smile | :)
GeneralRe: What about non-unicode builds ?memberPixiGreg12 Jul '03 - 9:26 
Orkblutt wrote:
many thanks pixigreg!! run very well now
 
You're welcome Blush | :O
 
But all the merit goes to Davide Calabro for this great control.
 
p i x i g r e g
GeneralRe: What about non-unicode builds ?memberOrkblutt12 Jul '03 - 12:24 
yes yes! Smile | :)
 
yet thanks Davide !!!
 
(not a problem that i'm using your control on my GUI Davide ??)
GeneralRe: What about non-unicode builds ?memberDavide Calabro13 Jul '03 - 2:06 
not a problem if your GUI is freeware.
 
Cheers,
 
SoftechSoftware
Davide Calabro'
davide_calabro@yahoo.com
http://www.softechsoftware.it
GeneralRe: What about non-unicode builds ?memberOrkblutt13 Jul '03 - 2:29 
yes it is... it's a GUI client of a distributed computing project...really free and maybe gives you money...lol
Smile | :)
You can download source client...
I'm using also other of your class like CButtonST, CShadeButtonST...
all your c++ class are great!!!
respects
GeneralRe: What about non-unicode builds ?memberDadhi oznobishin@yahoo.com15 Mar '05 - 3:09 
DWORD CCylinderProgressCtrlST::OnDrawText(Graphics* pGfx, int nPercentage, Rect* rpCtrl, Rect* rpEmpty, Rect* rpFull, BOOL bHorizontal)
{
	if (m_bShowText)
	{
		LOGFONTW		csLogFont;
		CFont*	pFont = GetParent()->GetFont();
		if ((pFont != NULL) && (GetObjectW(pFont->m_hObject, sizeof(csLogFont), &csLogFont) != 0))
		{
			StringFormat	sf;
			REAL			emSize = 0;
			SolidBrush		brText(m_cTextColor);
			RectF			rCtrl((REAL)rpCtrl->X, (REAL)rpCtrl->Y, (REAL)rpCtrl->Width, (REAL)rpCtrl->Height);
 
			emSize = (REAL)-MulDiv(csLogFont.lfHeight, 72, (int)pGfx->GetDpiY());
 
			Font			f(csLogFont.lfFaceName, emSize, FontStyleRegular, UnitPoint, NULL);
			sf.SetAlignment(StringAlignmentCenter);
			sf.SetLineAlignment(StringAlignmentCenter);
 
			pGfx->SetTextRenderingHint(TextRenderingHintAntiAlias);
 
			WCHAR			szText[256];
			swprintf(szText, L"%d%%", nPercentage);
			pGfx->DrawString(szText, -1, &f, rCtrl, &sf, &brText);
		} // if
	} // if

	return CYLINDERPROGRESSCTRLST_OK;
} // End of OnDrawText

GeneralRe: What about non-unicode builds ?memberMike Kondratyuk14 Aug '06 - 13:43 
Hello. If you replace A2W to T2W this code will be compiled in unicode and non-unicode applications.
Generalthe code above is not correct,fixed here!memberEversoft13 Apr '09 - 17:35 
note the last part of the snippet.
 
DWORD CCylinderProgressCtrlST::OnDrawText(Graphics* pGfx, int nPercentage, Rect* rpCtrl, Rect* rpEmpty, Rect* rpFull, BOOL bHorizontal)
{
if (m_bShowText)
{
CFont* pFont = NULL;

pFont = GetParent()->GetFont();
if (pFont)
{
TCHAR szText[256];
LOGFONT csLogFont;
StringFormat sf;
REAL emSize = 0;
SolidBrush brText(m_cTextColor);
RectF rCtrl((REAL)rpCtrl->X, (REAL)rpCtrl->Y, (REAL)rpCtrl->Width, (REAL)rpCtrl->Height);

pFont->GetLogFont(&csLogFont);

emSize = (REAL)-MulDiv(csLogFont.lfHeight, 72, (int)pGfx->GetDpiY());

#ifdef _UNICODE
Font f(csLogFont.lfFaceName, emSize, FontStyleRegular, UnitPoint, NULL);
#else
#if _ATL_VER >= 0x0700
CA2W lpszwFont((LPCSTR)csLogFont.lfFaceName);
Font f(lpszwFont, emSize, FontStyleRegular, UnitPoint, NULL);
#else
USES_CONVERSION;
Font f(A2W((LPCSTR)csLogFont.lfFaceName),
emSize, FontStyleRegular, UnitPoint, NULL);
#endif
#endif
sf.SetAlignment(StringAlignmentCenter);
sf.SetLineAlignment(StringAlignmentCenter);

_stprintf(szText, _T("%d%%"), nPercentage);
pGfx->SetTextRenderingHint(TextRenderingHintAntiAlias);

#ifdef _UNICODE
pGfx->DrawString(szText, -1, &f, rCtrl, &sf, &brText);
#else
#if _ATL_VER >= 0x0700
CA2W lpszwText((LPCSTR)szText);
pGfx->DrawString(lpszwText, -1, &f, rCtrl, &sf, &brText);
#else
pGfx->DrawString(A2W((LPCSTR)szText), -1, &f, rCtrl, &sf, &brText);
#endif
#endif
} // if
} // if

return CYLINDERPROGRESSCTRLST_OK;
} // End of OnDrawText
GeneralGot 2 compile errors.memberWREY2 Jul '03 - 17:42 
Is it the "gdiplus.dll" in the MS SDK that is required?
 
If it is, even though it is present with the other files in the folder (and present in the other directories also), the program is still not compiling properly.
 
Confused | :confused:

 
William
 
Fortes in fide et opere!
GeneralRe: Got 2 compile errors.memberDavide Calabro2 Jul '03 - 22:15 
What compile error do you get Confused | :confused:
 
SoftechSoftware
Davide Calabro'
davide_calabro@yahoo.com
http://www.softechsoftware.it
GeneralIt's working now !memberWREY3 Jul '03 - 7:18 
That was my fault. I had completely forgotten GDI+ works only with Unicode. When I changed the build configuration to Unicode, it compiled, linked and ran without error.
 
Thanks for sharing your work with the community, and thanks for the many helpful comments you placed in your work. Good man!
 
Cool | :cool:

 
William
 
Fortes in fide et opere!
GeneralRe: It's working now !memberPixiGreg8 Jul '03 - 4:03 
WREY wrote:
I had completely forgotten GDI+ works only with Unicode
 
GDI+ works with unicode disabled in your project !
You've just to pass unicode strings to it thanks to ATL conversion macros.
 
have a look at my post above !
 
pixigreg
QuestionWhy no interaction like a slider control?memberJohn A. Johnson2 Jul '03 - 10:50 
Cool | :cool:
 
Andy
AnswerRe: Why no interaction like a slider control?memberDavide Calabro2 Jul '03 - 22:15 
This is a progress control.

 
SoftechSoftware
Davide Calabro'
davide_calabro@yahoo.com
http://www.softechsoftware.it
GeneralRe: Why no interaction like a slider control?memberJohn A. Johnson2 Jul '03 - 22:20 
I know, that was why I posted the question.
 
There are applications, where the user can need to set the hight level of the cilynder (level regulation).
 
That meens that it would be nice to have a slider version too, or, a slider version with a method that enable disable the mouse interaction with the control.
 
Suspicious | :suss:
 
Andy
AnswerRe: Why no interaction like a slider control?memberCarlos H. Perez2 Jul '03 - 22:25 
A progress bar is meant to show a long operation progressing. A slider is meant to allow the user to graphically set the value of a property whithin a specific range. They both are different controls because they perform different UI tasks. Tyring to make one behave like other is just a sure way to confuse the user.
 
Imaging how useful it would be to have the progress bar used when you are installing Visual Studio .NET go back to zero after the program have been installing for an hour. Would that make sense at all?
 
You could certainly make a slider out of the cylinder, but they you have to create the properties for the cylinder to behave as a slider not a progress bar and you have to label the control as a "Slider" control not a ProgressBar/Slider control.
 
This remaind me of a programmer that wrote some code to make checkboxes behave like radio buttons. He was proud of his accomplishement. That was, of course, a horrible idea. Good UI are intuitive not "bizarre".
 
Regards,
Carlos.
 

 

GeneralRe: Why no interaction like a slider control?memberJohn A. Johnson3 Jul '03 - 0:28 
I'm sorry, my first answer was impulsive and not clear - but your was long and too much free speaking.
 
Let me explain.
 
This control is born as a custom ProgressControl, so it acts as a ProgressControl - STOP
 
Anyway it's a custom control, not a standard control, so in my opinion the comparison with the CHECKBOX and RADIO button doesent make sense, and I'm sorry to say, you will find tons of people that make "bizarre" things giving a free interpretation to what a standard control can do (I can fill a book of samples... and you can freely peek from VB beginning programmers).
 
Anyway it's not my case, you don't know me: STANDARD controls may act as their STANDARD behavior to prevent user confusion.
 
This is a CUSTOM control. The user wont find this in his normal Windows/Office form application interface, so he doesn’t know what the control can do until he wont play on it.
 
I work in the chemical field, and this control remembers me a recipient.
 
For this reason, what I see in my mind is not for a "long operation progressing" - for me it doesn’t make sense.
 
For sample, if it represents a silos stock, the level can move in both directions up and down depending on the filling or empting process of the recipient. So for me it make sense to "go back".
 
Another case is in the formula treatment for batch processing in a chemical production. Here normally you can find different recipients with different colors/levels that are representing chemical components. The user here have the needing to make a regulation to see a result of a simulation some ware (a graph or what else).
 
In this case, I approve: putting a slider near the cylinder is correct, but it will take space.
 
So maybe the problem is another: the name of the control. As a PROGRESS it must act as a PROGRESS, and, as a programmer, I'll be confused if it haves another behavior; but if this job was born with another name like:
 
CCylnderCtrl or CCylinderSlider or "what else"
 
than, I can hope in other behaviors, no?
 
As you can see, it's only a opinion problem. If you like it as a progress, you see it as a progress and want it as a progress, you are free, but I see it in a different way.
 
I really like Davide answer, it was direct and simple: "This is a progress control" (and I smile when I read it), but I'm sorry, your was not considering my needing or my point of view.
 
To end: this is born as a progress and it's called progress, but for me it doesn’t have an aspect of a progress (sorry to everybody, I know I'll loose popularity) - if I want a progress, I'll use a standard progress to prevent user confusion - here I can find the drawing code (or a link to it), so if I want, I can take it and modify for the behavior I need, no?
 
Suspicious | :suss:
 
Andy

GeneralRe: Why no interaction like a slider control?memberDavide Calabro3 Jul '03 - 6:41 
Your point of view is very clear. Honestly, I developed this control starting from my recent knob control that has support for mouse and keyboard events. So, this cylinder control HAD support for mouse and keyboard events that I removed before releasing it Frown | :(
Let me found time and maybe I'll re-implement these events...
BTW, please do not forget that I just converted/improved existing controls written in C# and that main credits must go to the original authors.
 
SoftechSoftware
Davide Calabro'
davide_calabro@yahoo.com
http://www.softechsoftware.it
AnswerRe: Why no interaction like a slider control?memberarmentage13 Jun '05 - 6:24 
No.

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

Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130523.1 | Last Updated 2 Jul 2003
Article Copyright 2003 by Davide Calabro
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid