Visual C++ and MFC Fundamentals Chapter 15: Fundamental Controls
- Change the ID of the new control to IDC_SHP_CIRCULAR and Add a Control
Variable for it named m_ShapeCircular - Access the OnPaint event of the CCircular class and implement it as follows:
void CCircular::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
// Do not call CPropertyPage::OnPaint() for painting messages// The location and dimension variable for the control
CRect ShapeRect;
// Create a cream color brush
CBrush BrushCream(RGB(255, 230, 205));
// Create an orange brush
CBrush BrushOrange(RGB(255, 128, 64));
// Create a brown pen
CPen PenBrown(PS_SOLID, 2, RGB(128, 0, 0));// Get the location and dimension of the control
m_ShapeCirc.GetWindowRect(&ShapeRect);// Convert the location and dimensions to client coordinates
ScreenToClient(&ShapeRect);// Select the cream brush to use
CBrush *pOldBrush = dc.SelectObject(&BrushCream);
// Paint the control's background to light blue
dc.Rectangle(ShapeRect);// Select the brown pen to paint
CPen *pOldPen = dc.SelectObject(&PenBrown);
// Select an orange brush
pOldBrush = dc.SelectObject(&BrushOrange);// Draw the circle
dc.Ellipse(40, 30, 120, 110);