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

Round / Spherical Progress Control

Rate me:
Please Sign up or sign in to vote.
3.83/5 (12 votes)
25 May 20031 min read 74.7K   1.9K   12   10
A progress control that can display progress as depth, area or volume of a sphere.

Sample Image - RoundProgress.jpg

Introduction

The title is pretty self explanatory. The control displays a circle / ellipse and fills it depending on the progress position. The circle's thickness and color can be changed. As can the colors of the filled and empty areas. The clever bit is how the position is represented. The progress can be used as proportional depth, area or volume of a sphere.

Background

In the MFC forums, someone was asking how to draw a partially filled circle. They had a need to display liquid level in a sphere. One bored Sunday afternoon later, my first article was born.

Using the code

This control simply subclasses an existing progress control. Either using class wizard, or by typing, subclass a progress control with CRoundProgressCtrl instead:

In your dialog definition:
class CMyDialog : public CDialog
{
...
protected:
CRoundProgressCtrl m_Sphere;
....
};

In your DoDataExchange method, place the following code:

void CMyDialog::DoDataExchange (CDataExchange *pDX)
{
....
DDX_Control(pDX, IDC_PROGRESS1, m_Progress1);
....
};

Or in the OnInitDialog method, have the following code:

BOOL CMyDialog::OnInitDialog()
{
....
m_Progress1.SubclassDlgItem (IDC_PROGRESS1, this);
CDialog::OnInitDialog();
....
}

CRoundProgressCtrl inherits all the methods of CProgressCtrl and adds a few of its own:

enum RoundStyle { roundDepth = 0, roundArea, roundVolume };
RoundStyle SetRoundStyle (RoundStyle r);
RoundStyle GetRoundStyle () const { return m_RoundStyle; }
UINT SetLineThickness (UINT l);
UINT GetLineThickness () const { return m_nLineThickness; }
COLORREF SetColorLine (COLORREF c);
COLORREF GetColorLine () const { return m_clrLine; }
COLORREF SetColorFill (COLORREF c);
COLORREF GetColorFill () const { return m_clrFill; }
COLORREF SetColorEmpty (COLORREF c);
COLORREF GetColorEmpty () const { return m_clrEmpty; }

The actions of these functions are fairly plain. The Set functions set the current setting before the change. Setting the colors to CLR_DEFAULT will set the control to use the same colors as a progress control. Setting the line thickness to 0 will turn it off. 1 or more will display the line.

Acknowledgements

As drawing the ellipse is a multistage operation, I've used Keith Rule's CMemDC class. I BitBlt the existing image to the memory DC first, in order to make the area outside the ellipse "transparent".

History

  • 26 May 2003

    Version 1.0 released. No known bugs, but I should hope not in such a small code snippet!

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
Software Developer (Senior)
Sweden Sweden
I have now moved to Sweden for love, and recently married a lovely Swede.


-----------------
I started programming on BBC micros (6502) when I was six and never quite stopped even while I was supposed to be studying physics and uni.

I've been working for ~13 years writing software for machine control and data analysis. I now work on financial transaction transformation software, for a Software company in Gamlastan, Stockholm.
Look at my articles to see my excellent coding skills. I'm modest too!

Comments and Discussions

 
GeneralSeries of circles Pin
Jolyn13-Dec-03 14:31
Jolyn13-Dec-03 14:31 
GeneralRe: Series of circles Pin
Iain Clarke, Warrior Programmer5-Jan-04 5:42
Iain Clarke, Warrior Programmer5-Jan-04 5:42 
GeneralOne step away from the IE Spinning Globe. Pin
WREY3-Jun-03 11:42
WREY3-Jun-03 11:42 
GeneralEclipsis as progress control Pin
Martin Holzherr26-May-03 21:14
Martin Holzherr26-May-03 21:14 
GeneralRe: Eclipsis as progress control Pin
Iain Clarke, Warrior Programmer26-May-03 22:36
Iain Clarke, Warrior Programmer26-May-03 22:36 
GeneralWeird Pin
dog_spawn26-May-03 4:03
dog_spawn26-May-03 4:03 
GeneralRe: Weird Pin
Iain Clarke, Warrior Programmer26-May-03 5:13
Iain Clarke, Warrior Programmer26-May-03 5:13 
GeneralRe: Weird Pin
yarp26-May-03 20:29
yarp26-May-03 20:29 
GeneralRe: Weird Pin
Ed Gadziemski27-May-03 3:27
professionalEd Gadziemski27-May-03 3:27 
GeneralRe: Weird Pin
Hofver2-Jun-03 21:07
Hofver2-Jun-03 21:07 

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.