Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Round / Spherical Progress Control

0.00/5 (No votes)
25 May 2003 1  
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