CPen redPen(PS_SOLID, 2, RGB(255, 0, 0));
CDC* pDC = GetDC(); CPen bluePen(PS_DOT, 1, RGB(0, 0, 255)); CPen* oldPen = pDC->SelectObject(&bluePen); pDC->MoveTo(10, 10); pDC->LineTo(100, 100); pDC->SelectObject(oldPen); ReleaseDC(pDC);In this example, a blue dotted pen object is created and selected for drawing on the device context. A line is then drawn from (10,10) to (100,100). The original pen object is restored before releasing the device context. Package library: MFC (Microsoft Foundation Classes) library.