CDC画图
RGB颜色模型,10种颜色配置pen:
- 橙色:RGB(255, 165, 0)
- 天蓝色:RGB(135, 206, 235)
- 深红色:RGB(139, 0, 0)
- 深绿色:RGB(0, 100, 0)
- 深蓝色:RGB(0, 0, 139)
- 靛青色:RGB(0, 139, 139)
- 深粉红色:RGB(139, 0, 139)
- 蓝紫色:RGB(138, 43, 226)
- 深橙色:RGB(255, 140, 0)
- 深棕色:RGB(139, 69, 19
CPen pen
pen.CreatePen(PS_SOLID, 1, RGB)
pMarkDC->SetTextColor(RGB(0, 0, 255));//设置文本颜色
pDC->DrawText(_T("你好,世界"),-1,&rt,DT_LEFT);
pDC->TextOut(50,50,_T("你好,世界"));
HPEN newPen = ::CreatePen(PS_SOLID,2,RGB(255,0,0));
HBRUSH newBrush = ::CreateSolidBrush(RGB(0,255,0));
HBRUSH oldBrush = SelectBrush(pDC->GetSafeHdc(),newBrush);
HFONT newFont = ::CreateFont(m_lf.lfHeight, // height of font
m_lf.lfWidth, // average character width
m_lf.lfEscapement, // angle of escapement
m_lf.lfOrientation, // base-line orientation angle
m_lf.lfWeight, // font weight
m_lf.lfItalic, // italic attribute option
m_lf.lfUnderline, // underline attribute option
m_lf.lfStrikeOut, // strikeout attribute option
m_lf.lfCharSet, // character set identifier
m_lf.lfOutPrecision, // output precision
m_lf.lfClipPrecision, // clipping precision
m_lf.lfQuality, // output quality
m_lf.lfPitchAndFamily, // pitch and family
m_lf.lfFaceName // typeface name
);
// 绘制矩形
CRect rect(50, 50, 200, 200); // 创建一个矩形,左上角坐标为(50, 50),宽度和高度都为150
CDC* pDC = GetDC(); // 获取设备上下文指针
pDC->Rectangle(rect); // 在设备上下文中绘制矩形
// 绘制圆
pDC->Ellipse(250, 50, 400, 200); // 在设备上下文中绘制圆,左上角坐标为(250, 50),宽度和高度都为150
// 绘制线
pDC->MoveTo(500, 50); // 移动到起始点(500, 50)
pDC->LineTo(650, 200); // 在设备上下文中绘制一条直线,到终点(650, 200)
// 绘制旋转矩形
CRect rotateRect(700, 50, 850, 200); // 创建一个矩形,左上角坐标为(700, 50),宽度和高度都为150
pDC->SelectStockObject(BLACK_BRUSH); // 选择用黑色绘制矩形的画刷
pDC->MoveTo(rotateRect.left, rotateRect.top + rotateRect.Height() / 2); // 移动到矩形的中心点
pDC->AngleArc(rotateRect.left + rotateRect.Width() / 2, rotateRect.top + rotateRect.Height() / 2, rotateRect.Width() / 2, 0, 90); // 绘制一个旋转角度为90度的矩形
ReleaseDC(pDC); // 释放设备上下文指针