Click here to Skip to main content
Click here to Skip to main content
Go to top

Round / Spherical Progress Control

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

Share

About the Author

Iain Clarke, Warrior Programmer
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 PinmemberJolyn13-Dec-03 14:31 
GeneralRe: Series of circles PinmemberIain Clarke5-Jan-04 5:42 
GeneralOne step away from the IE Spinning Globe. PinmemberWREY3-Jun-03 11:42 
GeneralEclipsis as progress control PinmemberMartin Holzherr26-May-03 21:14 
GeneralRe: Eclipsis as progress control PinmemberIain Clarke26-May-03 22:36 
GeneralWeird Pinmemberdog_spawn26-May-03 4:03 
GeneralRe: Weird PinmemberIain Clarke26-May-03 5:13 
GeneralRe: Weird Pinmemberyarp26-May-03 20:29 
GeneralRe: Weird PinmemberEd Gadziemski27-May-03 3:27 
GeneralRe: Weird PinmemberSimon Hofverberg2-Jun-03 21:07 

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
Web03 | 2.8.140916.1 | Last Updated 26 May 2003
Article Copyright 2003 by Iain Clarke, Warrior Programmer
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid