11.04.2014 Views

Advanced MFC Programming

Advanced MFC Programming

Advanced MFC Programming

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 8. DC, Pen, Brush and Palette<br />

}<br />

CGDIDoc* pDoc = GetDocument();<br />

ASSERT_VALID(pDoc);<br />

pen.CreatePen(PS_SOLID, 1, RGB(255, 0, 255));<br />

brush.CreateHatchBrush(HS_DIAGCROSS, RGB(255, 255, 0));<br />

ptrPenOld=pDC->SelectObject(&pen);<br />

ptrBrushOld=pDC->SelectObject(&brush);<br />

pDC->TextOut<br />

(<br />

0, 0,<br />

"pDC->Chord(CRect(5, 5, 60, 70), CPoint(0, 80), CPoint(100, 0));"<br />

);<br />

pDC->Chord(CRect(5, 5, 60, 70), CPoint(0, 80), CPoint(100, 0));<br />

pDC->TextOut<br />

(<br />

0, 75,<br />

"pDC->DrawFocusRect(CRect(5, 95, 60, 150));"<br />

);<br />

pDC->DrawFocusRect(CRect(5, 95, 60, 150));<br />

pDC->TextOut<br />

(<br />

0, 155,<br />

"pDC->Pie(CRect(5, 165, 60, 200), CPoint(5, 165), CPoint(60, 165));"<br />

);<br />

pDC->Pie(CRect(5, 165, 60, 200), CPoint(5, 165), CPoint(60, 165));<br />

pts[0]=CPoint(5, 225);<br />

pts[1]=CPoint(100, 255);<br />

pts[2]=CPoint(50, 360);<br />

pts[3]=CPoint(5, 360);<br />

pts[4]=CPoint(50, 310);<br />

pts[5]=CPoint(50, 260);<br />

pDC->TextOut<br />

(<br />

0, 210,<br />

"pDC->Polygon(pts, 6);"<br />

);<br />

pDC->Polygon(pts, 6);<br />

pDC->TextOut<br />

(<br />

0, 370,<br />

"pDC->RoundRect(rect, CPoint(20, 10));"<br />

);<br />

rect=CRect(5, 385, 100, 435);<br />

pDC->RoundRect(rect, CPoint(20, 10));<br />

rect=CRect(5, 460, 100, 510);<br />

pDC->TextOut<br />

(<br />

0, 445,<br />

"pDC->Draw3dRect(rect, RGB(127, 127, 127), RGB(63, 63, 63));"<br />

);<br />

pDC->Draw3dRect(rect, RGB(255, 0, 0), RGB(0, 255, 255));<br />

pDC->SelectObject(ptrPenOld);<br />

pDC->SelectObject(ptrBrushOld);<br />

The following is the explanation of the functions used above:<br />

BOOL CDC::TextOut(int x, int y, const CString& str);<br />

This function outputs a text string at the specified x-y coordinates. The string is stored in str<br />

parameter. Text color and background color can be set by using functions CDC::SetTextColor(…) and<br />

CDC::SetBkColor(…). Background mode (specifies if text has transparent or opaque background) can be set<br />

by using function CDC::SetBkMode(…).<br />

BOOL CDC::Chord(LPCRECT lpRect, POINT ptStart, POINT ptEnd);<br />

215

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!