欢迎来到三一办公! | 帮助中心 三一办公31ppt.com(应用文档模板下载平台)
三一办公
全部分类
  • 办公文档>
  • PPT模板>
  • 建筑/施工/环境>
  • 毕业设计>
  • 工程图纸>
  • 教育教学>
  • 素材源码>
  • 生活休闲>
  • 临时分类>
  • ImageVerifierCode 换一换
    首页 三一办公 > 资源分类 > PPT文档下载  

    实验一图形程序设计基础.ppt

    • 资源ID:6270413       资源大小:438KB        全文页数:18页
    • 资源格式: PPT        下载积分:15金币
    快捷下载 游客一键下载
    会员登录下载
    三方登录下载: 微信开放平台登录 QQ登录  
    下载资源需要15金币
    邮箱/手机:
    温馨提示:
    用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)
    支付方式: 支付宝    微信支付   
    验证码:   换一换

    加入VIP免费专享
     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    实验一图形程序设计基础.ppt

    实验一 图形程序设计基础,一.概述:,本实验是在Microsoft Visual C+6.0平台上,建立一个Project,并在该Project的View文件内,找到Visual C+6.0自动创建的CView类的虚拟成员函数OnDraw(CDC*pDC),并在该函数内添加相应的绘图程序,绘图程序通过CDC类指针pDC调用相应的绘图土函数,来完成所需图形的绘制。因此,在此实验中,除了要掌握Visual C+6.0平台上编制图形程序的步骤之外,还应初步了解MFC的结构,尤其需要了解与绘图有关的相关类的关系和类中成员函数的调用方式。,MFC结构如下:,二实验的主要目的:,1、让学生掌握利用Microsoft Visual C+6.0平台,进行图形程序设计的基本方法与步骤;2、训练学生利用计算机分析和解决实际问题的能力;3、锻炼学生撰写科技实验报告的能力。,三实验步骤:,建立工程:打开Visual C+;选择FileNewProjectsMFC AppWizardexe,在Project Name内输入工程名(如FtistP),并在Location选择程序文件存储路径,最后点击OK。,2.选择欲创建的文档类型:,在Step1对话框中,选择Single Document或Multiple Documents或Dialog based中任意一项均可,但后续操作不一样。(如选Multiple Documents)点击Finish(若还有其他需要则选Next);,在如下New Project Information框内下点击OK。,3.编写图形程序:,在如上图所示的此新建的Project内,Workspace视窗下选择FileView,然后点击FirstP Files展开它,在Source Files中找到FirstPView.cpp文件,在该文件中找到CView类下的列函数:void CFirstPView:OnDraw(CDC*pDC)CFirstPDoc*pDoc=GetDocument();ASSERT_VALID(pDoc);/TODO:add draw code for native data here(添加代码处),在该函数内添加相应的绘图程序代码,图形形状不作统一要求,可自由设计,代码自己编写,也可用教材上P20实例来练习。,教材上P20实例代码如下:/使用缺省画笔画了一条直线,画笔的属性是实线型、1个像素宽、黑色 pDC-MoveTo(100,100);pDC-LineTo(200,200);CPen*pOldPen;/申请一个画笔指针,用于保存当前设备环境下的画笔 CPen dashPen;/以下创建画笔并绘制直线/创建一个画笔,其属性是虚线型、1个像素宽、红色 dashPen.CreatePen(PS_DASH,1,RGB(255,0,0);/PS_SOLID:Pen is solid;/PS_DASH:Pen is dashed;PS_DOT:Pen is dotted;PS_DASHDOT:Pen has alternating dashes and dots/PS_DASHDOTDOT;PS_INSIDEFRAME:Pen is solid;PS_NULL:Pen is invisible pOldPen=pDC-SelectObject(/再次使用原画笔再绘制直线,4编译调试程序,直到通过运行后得到需要的结论。,注:若在:void CFirstPView:OnDraw(CDC*pDC)CFirstPDoc*pDoc=GetDocument();ASSERT_VALID(pDoc);/TODO:add draw code for native data here。函数前添加下列函数,即可在相应线段中插入字符“0”,VOID CALLBACK DrawZero(int X,int y,LPARAM lpData)CDC*pDC;pDC=(CDC*)lpData;if(X%20=0)pDC-TextOut(X,y,_T(0);,再在书上代码:pDC-MoveTo(100,100);pDC-LineTo(200,200);下添加下列语句::LineDDA(100,100,200,200,(LINEDDAPROC)DrawZero,(long)pDC);/画“0”函数即可在直线段(100,100)到(200,200)上每隔20个段位长度处输出一个“0”符号。其运行结果如下图所示:,5.分析总结,并提交实验报告。(略),注:各函数说明如下。1CDC:MoveTo CPoint MoveTo(int x,int y);Return Value The x-and y-coordinates of the previous position as a CPoint object.Parametersx Specifies the logical x-coordinate of the new position.y Specifies the logical y-coordinate of the new position.Remarks Moves the current position to the point specified by x and y(or by point).,2CDC:LineTo BOOL LineTo(int x,int y);Return Value Nonzero if the line is drawn;otherwise 0.Parametersx Specifies the logical x-coordinate of the endpoint for the line.y Specifies the logical y-coordinate of the endpoint for the line.Remarks Draws a line from the current position up to,but not including,the point specified by x and y(or point).The line is drawn with the selected pen.The current position is set to x,y or to point.,3CPen:CreatePen BOOL CreatePen(int nPenStyle,int nWidth,COLORREF crColor);Return Value Nonzero,or the handle of a logical pen,if successful;otherwise 0.ParametersnPenStyle Specifies the style for the pen.For a list of possible values,see the nPenStyle parameter in the CPen constructor.nWidth Specifies the width of the pen.if this value is 0,the width in device units is always 1 pixel,regardless of the mapping mode.crColor Contains an RGB color for the pen.Remarks The CreatePen initializes a pen with the specified style,width,and color.The pen can be subsequently selected as the current pen for any device context.,4CDC:SelectObject CPen*SelectObject(CPen*pPen);Return Value A pointer to the object being replaced.This is a pointer to an object of one of the classes derived from CGdiObject.The return value is NULL if there is an error.ParameterspPen A pointer to a CPen object to be selected.Remarks Selects an object into the device context.,5、TextOut(x,y,_T(“0”);在点(x,y)处输出符号“0”。,本实验讲解完毕 谢谢!,

    注意事项

    本文(实验一图形程序设计基础.ppt)为本站会员(小飞机)主动上传,三一办公仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知三一办公(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    备案号:宁ICP备20000045号-2

    经营许可证:宁B2-20210002

    宁公网安备 64010402000987号

    三一办公
    收起
    展开