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
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!