Visual C++ and MFC Fundamentals Chapter 17: Track-Based Controls
void CExerciseView::OnDraw(CDC* pDC)
{
// TODO: Add your specialized code here and/or call the base class
CFont font;
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;
// Create a bold font
font.CreateFont(42, 14, 0, 0,
FW_HEAVY, FALSE, FALSE, FALSE, ANSI_CHARSET,
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY, DEFAULT_PITCH | FF_ROMAN,
"Times New Roman");
CFont *pFont = pDC->SelectObject(&font);
// We need the current width of the client area
GetClientRect(&Recto);
// Create a string label and get its length
const char *lblEmplApp = "Employment Application";
int Len = strlen(lblEmplApp);
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);
// We want the text to be transparent
pDC->SetBkMode(TRANSPARENT);
// Draw the label
pDC->SetTextColor(RGB(192, 192, 192));
pDC->TextOut(16, 10, lblEmplApp, Len);
// Draw the label's shadow
pDC->SetTextColor(RGB(0, 0, 255));
pDC->TextOut(10, 8, lblEmplApp, Len);
// Restore the GDI tools
pDC->SelectObject(pFont);
font.DeleteObject();
pDC->SelectObject(pnOld);
pDC->SelectObject(brOld);
}
- Test the application