Visual C++ and MFC Fundamentals Chapter 17: Track-Based Controls
- Click Finish.
- If you are using MSVC 7, in the Resource View, expand the Dialog folder
Click the TODO line and press Delete - In the Class View, click the view node and, in the Properties window, click the
Overrides button
- Click OnDraw to display its combo box. Click the arrow and select
OnDraw - Implement it as follows:
void CExerciseView::OnDraw(CDC* pDC)
{
// TODO: Add your specialized code here and/or call the base class
CBrush BrushWhite(RGB(255, 255, 255));
CPen PenWhite(PS_SOLID, 1, RGB(255, 255, 255));
CPen PenNavy(PS_SOLID, 2, RGB(0, 64, 128));
CRect Recto;
// We need the current width of the client area
GetClientRect(&Recto);
// Select a color for the brush and the pen
CPen *pnOld = pDC->SelectObject(&PenWhite);
CBrush *brOld = pDC->SelectObject(&BrushWhite);
// Draw a rectangle
pDC->Rectangle(0, 0, Recto.Width(), 68);
// Draw a (heavy) line under the rectangle
pnOld = pDC->SelectObject(&PenNavy);
pDC->MoveTo(0, 68);
pDC->LineTo(Recto.Width(), 68);
// Restore the GDI tools
pDC->SelectObject(pnOld);
pDC->SelectObject(brOld);
}