资源描述:
《实验一mfc基本绘图》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、C学与计算科学系学生实验报告实验课程名称:计算机图形学实验内容:实验一MFC基本绘g系别:年级:专业班:_学生姓名:学号:幵课时间:年下学期成绩实验指导教师一、实验要求1.按照教材第40页2.2节所介绍的操作步骤,熟悉MFC应用程序的创建过程,并完成第50页的例2—5。2.在上而程序的基础上,通过设置不同的画笔和画刷,至少实现8个不同图形的绘制,如:椭圆、矩形、实线、虚线、位图显示、五角星(多边形)、圆弧、扇形、Bezier曲线等等。二、实验过程1.启动Visval6.0++,创建MFC单文档工程。2.在MFC的OnDraw(CDC*pDC)中“//TO
2、DO:adddrawcodefornativedatahere”下进行编程。3.建立直角坐标系,并标出x,y轴和原点0。4.在坐标系里画图。5.用图片填充背景时要先将图片导入MFCresources中。6.画五角星时在头文件中加入以下代码:#include"math.h"#definePI3.1415926#defineRound(d)int(floor(d+0.5))三、程序代码voidCMywork1View::OnDraw(CDC*pDC)CMyworklDoc*pDoc=GetDocument();ASSERT_VALID(pDoc);//TOD
3、O:adddrawcodefornativedatahereCRectrect;//定义矩阵GetClientRect(&rect);//获得客户区矩阵pDC-〉SetMapMode(MM_ANISOTROPIC);//设置映射模式pDC-〉SetWindowExt(100,100);//设置窗口pDC-〉SetViewportExt(100,100);//设置视区:x轴水平向右为正,y轴垂直向上为正pDC-〉SetViewportOrg(rect.Width()/2,rect.Height()/2);//设置客户区中心为坐标系原点rect.Offset
4、Rect(-rect.Width()/2,-rect.Height()/2);//客户区矩阵校正//建立坐标系CPenNewPen,*pOldPen;NewPen.CreatePen(PS_SOLID,l,RGB(0,255,0));//画实线,选择绿色画笔pOldPen=pDC->SelectObject(&NewPen);pDC->MoveTo(-rect.right,0);pDC->LineTo(rect.right,0);pDC->MoveTo(0,-rect.bottom);pDC->LineTo(0,rect.bottom);pDC->Mov
5、eTo(rect.right,0);pDC->LineTo(rect.right-10,-7);pDC-〉MoveTo(rect.right,0);pDC->LineTo(rect.right-10,7);pDC-〉MoveTo(0,-rect.bottom);pDC-〉LineTo(7,10-rect.bottom);pDC->MoveTo(0,-rect.bottom);pDC->LineTo(-7,10-rect.bottom);pDC->TextOut(rect.right-15,5,"xM);pDC-〉TextOut(25,15-rect.bo
6、ttom,"y"pDC->TextOut(-15,10,nOM);//自定义坐标轴//画x轴的箭头//画x轴的箭头//圓y轴的箭头//画y轴的箭头//显示x轴//显示y轴//显示原点//直线…画实线1CPointA(50,50),B(450,300);CPenNewPenl,*pOldPen1;NewPen1.CreatePen(PS_SOLID,1,RGB(0,225,225));//画实线,选择青色画笔pOldPen1=pDC->SelectObject(&NewPen1);pDC-〉MoveTo(A);pDC-〉LineTo(B);pDC->Sel
7、ectObject(pOldPen1);pDC->TextOut(50,50;A');pDC-〉TextOut(450,300,'B’);pDC-〉TextOut(200,200,"实线’•);//直线…画虚线2CPointC(300,150),D(600,100);CPenNewPen2,*pOldPen2;NewPen2.CreatePen(PS_DASH,l,RGB(225,0,0));//画虚线,选择红色画笔pOldPen2=pDC->SelectObject(&NewPen2);pDC-〉MoveTo(C);pDC-〉LineTo(D);pDC
8、->SelectObject(pOldPen2);t(寸qsnjgplod)p3