标签:直线 getc 引入 dbr 右上角 delete viewport ldb image
CRect rect; //定义矩形 GetClientRect(&rect); //获得客户区矩形 pDC->SetMapMode(MM_ANISOTROPIC); //设置映射模式 pDC->SetWindowExt(rect.Width(),rect.Height()); //设置窗口 pDC->SetViewportExt(rect.Width(),-rect.Height()); //设置视区:x轴水平向右为正,y轴垂直向上为正 pDC->SetViewportOrg(rect.Width()/2,rect.Height()/2); //设置客户区中心为坐标系原点 rect.OffsetRect(-rect.Width()/2,-rect.Height()/2); //客户区矩形校正 CPen penBlue(PS_SOLID,5,RGB(0,0,255)); //定义5个像素宽的蓝色画笔 CPen *pOldPen=pDC->SelectObject(&penBlue); CBrush brushRed(RGB(255,0,0)); //定义红色画刷 CBrush *pOldBrush=pDC->SelectObject(&brushRed); pDC->SetPolyFillMode(WINDING); //设置填充模式 int r=200; //正五边形外接圆半径 CPoint p[5]; //定义正五边形顶点数组 double Beta=2*PI/5; //定义每个顶点的圆心角β double Alpha=PI/10; //定义初始角α for(int i=0;i<5;i++) { p[i].x=Round(r*cos(i*Beta+Alpha)); p[i].y=Round(r*sin(i*Beta+Alpha)); } CPoint v[5]; v[0]=p[0];v[1]=p[2];v[2]=p[4];v[3]=p[1];v[4]=p[3]; //转储顶点 pDC->Polygon(v,5); //绘制五角星 pDC->SelectObject(pOldPen); //恢复画笔 pDC->SelectObject(pOldBrush); //恢复画刷
注意:在该例程中用到了三角函数,要包含数学头文件;用到了圆周率π的值,需要把它宏定义为PI;由于五边形的顶点数组的计算值为浮点型数据,存储为CPoint类型时需要进行舍入处理。为此在文件头添加了以下编译预处理语句:
#include<math.h> #define PI 3.1415926 #define Round(d) int(floor(d+0.5))
CRect rect; //定义矩形 GetClientRect(&rect); //获得客户区矩形 pDC->SetMapMode(MM_ANISOTROPIC); //设置映射模式 pDC->SetWindowExt(rect.Width(),rect.Height()); //设置窗口 pDC->SetViewportExt(rect.Width(),-rect.Height()); //设置视区:x轴水平向右为正,y轴垂直向上为正 pDC->SetViewportOrg(rect.Width()/2,rect.Height()/2); //设置客户区中心为坐标系原点 rect.OffsetRect(-rect.Width()/2,-rect.Height()/2); //客户区矩形校正 CPoint p[7]; //定义顶点数组 p[0]=CPoint(-160,20);p[1]=CPoint(-240,100); p[2]=CPoint(-280,0);p[3]=CPoint(-240,-100); p[4]=CPoint(-180,-40);p[5]=CPoint(-140,-100);p[6]=CPoint(-60,40); CBrush NewBrush; NewBrush.CreateSolidBrush(RGB(255,0,0)); CBrush *pOldBrush=pDC->SelectObject(&NewBrush); pDC->BeginPath(); pDC->MoveTo(p[0]); //绘制左侧多边形 for(int i=1;i<7;i++) pDC->LineTo(p[i]); pDC->LineTo(p[0]); pDC->EndPath(); pDC->FillPath(); p[0]=CPoint(200,20);p[1]=CPoint(120,100); p[2]=CPoint(80,0);p[3]=CPoint(120,-100); p[4]=CPoint(180,-40);p[5]=CPoint(220,-100);p[6]=CPoint(300,40); pDC->BeginPath(); pDC->MoveTo(p[0]); for(i=1;i<7;i++) //绘制右侧多边形 pDC->LineTo(p[i]); pDC->LineTo(p[0]); pDC->EndPath(); pDC->StrokeAndFillPath(); //StrokeAndFillPath 填充路径层 pDC->SelectObject(pOldBrush); NewBrush.DeleteObject();
CRect rect; //定义矩形 GetClientRect(&rect); //获得客户区矩形 pDC->SetMapMode(MM_ANISOTROPIC); //设置映射模式 pDC->SetWindowExt(rect.Width(),rect.Height()); //设置窗口 pDC->SetViewportExt(rect.Width(),-rect.Height()); //设置视区:x轴水平向右为正,y轴垂直向上为正 pDC->SetViewportOrg(rect.Width()/2,rect.Height()/2); //设置客户区中心为坐标系原点 rect.OffsetRect(-rect.Width()/2,-rect.Height()/2); //客户区矩形校正 CPoint p[7]; p[0]=CPoint(-350,-100);p[1]=CPoint(-250,100); p[2]=CPoint(0,130);p[3]=CPoint(50,-50); double k=(p[3].y-p[2].y)/(p[3].x-p[2].x); double x=90,y=k*(x-p[3].x)+p[3].y; p[4]=CPoint(Round(x),Round(y));p[5]=CPoint(350,-20);p[6]=CPoint(250,130); for(int i=0;i<7;i++) { if(0==i) pDC->MoveTo(p[i]); else pDC->LineTo(p[i]); pDC->Ellipse(p[i].x-5,p[i].y-5,p[i].x+5,p[i].y+5); //黑色实心圆绘制控制点 } CPen NewPen,*pOldPen; NewPen.CreatePen(PS_SOLID,1,RGB(0,0,255)); //蓝色画笔绘制样条 pOldPen=pDC->SelectObject(&NewPen); pDC->PolyBezier(p,7); //绘制Bezier样条 pDC->SelectObject(pOldPen);
在Resource View 画板里选中Test resources,右击,在弹出的菜单里选择引入...,
注意:图片后缀名必须是.bmp
效果如下:
CRect rect; //定义矩形 GetClientRect(&rect); //获得客户区矩形 pDC->SetMapMode(MM_ANISOTROPIC); //设置映射模式 pDC->SetWindowExt(rect.Width(),rect.Height()); //设置窗口 pDC->SetViewportExt(rect.Width(),-rect.Height()); //设置视区:x轴水平向右为正,y轴垂直向上为正 pDC->SetViewportOrg(rect.Width()/2,rect.Height()/2); //设置客户区中心为坐标系原点 rect.OffsetRect(-rect.Width()/2,-rect.Height()/2); //客户区矩形校正 CBitmap NewBitmap; NewBitmap.LoadBitmap(IDB_BITMAP1); CBrush NewBrush,*pOldBrush; NewBrush.CreatePatternBrush(&NewBitmap); //新建模式画刷,图片作为模式刷 pOldBrush=pDC->SelectObject(&NewBrush); CPen *pOldPen; pOldPen=(CPen*)pDC->SelectStockObject(NULL_PEN); CPoint ld,rt,sp,eq; ld=CPoint(-400,-600),rt=CPoint(400,200); //外接矩形的左下角点ld、右上角点rt sp=CPoint(400,0),eq=CPoint(-400,0); //椭圆弧的起点sp和终点eq pDC->Pie(CRect(ld,rt),sp,eq); pDC->SelectObject(pOldBrush); NewBitmap.DeleteObject(); ld=CPoint(-80,-280),rt=CPoint(80,-120); sp=CPoint(400,0),eq=CPoint(-400,0); pDC->Pie(CRect(ld,rt),sp,eq); //使用默认画刷填充 pDC->SelectObject(pOldPen);
标签:直线 getc 引入 dbr 右上角 delete viewport ldb image
原文地址:http://www.cnblogs.com/OctoptusLian/p/6659566.html