//清空背景
SolidBrush brush(Color(255, 255,255,255));
using namespace Gdiplus;
pGraphics->FillRectangle(&brush,0,0,m_winWidth,m_winHeight);
//画笔准备
int PenWidth = theApp.m_optionDlg.m_iSliderPenWidth;
Pen pen(Color(255, 0, 0, 255), PenWidth);
Pen pen2(Color(255, 255, 0, 0), PenWidth);
//-------------------------------------------
//画对角线
pGraphics->DrawLine(&pen,pRect->left,pRect->top,pRect->right, pRect->bottom);
pGraphics->DrawLine(&pen,pRect->right,pRect->top,pRect->left, pRect->bottom);
//-------------------------------------------
//画格子
for (int y = 0; y < m_winHeight; y += 10) {
pGraphics->DrawLine(&pen, 0, y, m_winWidth, y);
}
for (int x = 0; x < m_winWidth; x += 10) {
pGraphics->DrawLine(&pen, x, 0, x, m_winHeight);
}
//-------------------------------------------
//画圆弧
pGraphics->DrawArc(&pen2, 0,0, 100,100, 0.0f,360.0f);
//-------------------------------------------
//画填充多边形
SolidBrush fillPolyBrush(Color(128, 255, 0, 0));
Point point1(100, 100);
Point point2(200, 130);
Point point3(250, 160);
Point point4(150, 200);
Point point5( 70, 130);
Point points[5] = {point1, point2, point3, point4, point5};
pGraphics->FillPolygon(&fillPolyBrush, points, 5);
//-------------------------------------------
//字符串
if (theApp.m_optionDlg.m_strDrawString != "") {
// UNICODE字串变换
_bstr_t bstr(theApp.m_optionDlg.m_strDrawString);
Font myFont(L"Arial", 42);
PointF origin(0.0f, 0.0f);
SolidBrush blackBrush(Color(255, 0, 0, 0));
StringFormat format;
format.SetAlignment(StringAlignmentCenter);
pGraphics->DrawString(
bstr,
bstr.length(),
&myFont,
origin,
&blackBrush);
}
|
//清空背景
CBrush brush;
brush.CreateSolidBrush(RGB(255, 255, 255));
//初始画刷保存
CBrush OrigBrush;
CBrush *pTmpBrush = (CBrush*)pDC->SelectObject(brush);
OrigBrush.FromHandle((HBRUSH)pTmpBrush);
pDC->Rectangle(pRect);
pDC->SelectObject(&OrigBrush);
brush.DeleteObject();
//画笔准备
int PenWidth = theApp.m_optionDlg.m_iSliderPenWidth;
CPen pen(PS_SOLID, PenWidth, RGB(0, 0, 255));
CPen pen2(PS_SOLID, PenWidth, RGB(255, 0, 0));
//初始画笔保存
CPen OrigPen;
CPen *pTmpPen = (CPen*)pDC->SelectObject(pen);
OrigPen.FromHandle((HPEN)pTmpPen);
//-------------------------------------------
//画笔准备
pDC->MoveTo(pRect->left, pRect->top);
pDC->LineTo(pRect->right, pRect->bottom);
pDC->MoveTo(pRect->right, pRect->top);
pDC->LineTo(pRect->left, pRect->bottom);
//-------------------------------------------
//画格子
for (int y = 0; y < m_winHeight; y += 10) {
pDC->MoveTo(0, y);
pDC->LineTo(m_winWidth, y);
}
for (int x = 0; x < m_winWidth; x += 10) {
pDC->MoveTo(x, 0);
pDC->LineTo(x, m_winHeight);
}
pDC->SelectObject(&OrigPen);
pen.DeleteObject();
//-------------------------------------------
//画圆弧
long width, height;
POINT cpos;
double r,srad,erad;
const double m_pi = 3.1415926535758932;
width = 100 - 0;
height = 100 - 0;
cpos.x = 0 + (long)(width / 2.0);
cpos.y = 0 + (long)(height / 2.0);
r = max(width / 2.0, height / 2.0);
srad = 0.0 * m_pi / 180.0;
erad = (0.0 + 360.0) * m_pi / 180.0;
pTmpPen = (CPen*)pDC->SelectObject(pen2);
pDC->Arc(0,0, 100,100,
cpos.x + (long)(r * cos(srad)),
cpos.y + (long)(r * sin(srad)),
cpos.x + (long)(r * cos(erad)),
cpos.y + (long)(r * sin(erad)));
pDC->SelectObject(&OrigPen);
pen2.DeleteObject();
//-------------------------------------------
//画填充多边形
CBrush fillPolyBrush;
fillPolyBrush.CreateSolidBrush(RGB(255, 0, 0));
pTmpBrush = (CBrush*)pDC->SelectObject(fillPolyBrush);
CPoint point1(100, 100);
CPoint point2(200, 130);
CPoint point3(250, 160);
CPoint point4(150, 200);
CPoint point5( 70, 130);
CPoint points[5] = {point1, point2, point3, point4, point5};
pDC->Polygon(points, 5);
pDC->SelectObject(&OrigBrush);
fillPolyBrush.DeleteObject();
//-------------------------------------------
//符串
if (theApp.m_optionDlg.m_strDrawString != "") {
//UNICODE字串变换
_bstr_t bstr(theApp.m_optionDlg.m_strDrawString);
CFont myFont;
CFont OrigFont;
myFont.CreatePointFont(420, "Arial");
CFont *pTmpFont = (CFont*)pDC->SelectObject(myFont);
OrigFont.FromHandle((HFONT)pTmpFont);
CBrush blackBrush;
blackBrush.CreateSolidBrush(RGB(0, 0, 0));
pTmpBrush = (CBrush*)pDC->SelectObject(blackBrush);
//pDC->SetTextAlign(TA_CENTER);
pDC->TextOut(0, 0, bstr, bstr.length());
pDC->SelectObject(&OrigFont);
myFont.DeleteObject();
}
|