简单画图程序课程设计报告.doc_第1页
简单画图程序课程设计报告.doc_第2页
简单画图程序课程设计报告.doc_第3页
简单画图程序课程设计报告.doc_第4页
简单画图程序课程设计报告.doc_第5页
已阅读5页,还剩6页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

简单画图程序1 基本功能描述1) 在单文档菜单中,在菜单行中可插入一个菜单项,命名为绘图,在下拉菜单中可分别设置绘制的图形形状,如直线、矩形及椭圆,随手画选项,有1-5可供选择,按默认的画笔,画刷来绘制选择的图形。 2) 选择好图形后,通过鼠标可以绘制出相应的直线,矩形或椭圆,鼠标的按下确定图形的起点,鼠标的拖动则确定了图形的终点,即通过鼠标的拖动来决定图形的大小,当鼠标弹起,此图形则绘制完毕。2 设计思路 1) 对需要用到的变量进行初始化。2) 选择相应的图形之后就响应相应的消息处理函数。选择不同的线宽,即可改变画笔的属性。3) 鼠标的按下响应函数onlbuttondown(),捕捉鼠标当前位置得到起点的坐标,鼠标的拖动响函数onmousemove()改变终点的坐标,鼠标的弹起响应onlbuttonup(),确定终点坐标,刷新,得到绘制图形。4) 选择图形或其它属性,可进行下一次绘制。 3 软件设计3.1 设计步骤1)创建单文档创建一个mfc appwizardexe工程,命名为“draw”,并创建单文档。创建成功后,系统自动生成相应的类。2) 编辑菜单添加需要的菜单项,并在菜单的属性中设定好所对应的id,(其中线宽菜单为弹出菜单,只需在菜单项目属性中的弹出选项前打勾即可,分隔线亦只需在菜单项目属性中选中分隔符选项即可)。建立类向导,在视图类cdrawview中,对各菜单项添加对应的command消息处理函数,部分菜单项还添加对应的update_command_ui消息函数,。 建立类向导在插入处选择资源,新建工具栏, 在工具栏上添加相应的按钮,在属性处更改其id, 4)在相应消息函数处添加代码,实现其功能建立类向导,在视图类cdrawview中,添加wm_paint消息,以及wm_lbuttondown、wm_lbuttonup、wm_mousemove消息,并在其中添加相应的代码。 3.3 关键功能实现1)选择要绘制的图形在直线、矩形以及椭圆的消息处理函数里为shape分别赋值为1,2,3,在onpaint()函数里添加3个if语句的代码来这实现这三个图形的绘制:当选择画直线时,shape=1,则执行绘制直线代码,当选择画矩形时,shape =2,则执行绘制矩形的代码,当性选择画椭圆时,shape=3,则执行绘制椭圆的代码。5)绘制图形 鼠标左键按下,则捕获鼠标此时的位置坐标为画图的起点,此时在onlbuttondown()函数里,将捕获的坐标值赋给定义作为起点的变量opoint;按下鼠标左键拖动鼠标时,捕捉鼠标当前位置坐标值为终点坐标值,此时在onmousemove()函数里,把捕获的坐标值赋给定义作为终点的变量cpoint,onpaint()中绘图的代码中的坐标都得到了,进行绘图;鼠标左键弹起时,此时绘图结束,鼠标弹起时所在位置就是画图的最终终点位置,画图结束后,刷新窗口,以便重新画图,此时执行的是onlbuttonup()函数。4 结论与心得体会 这次课程设计我成功的完成了。通过本次课程设计,我完成了用移动鼠标对直线,矩形,椭圆的简单绘制工具的的制作,其中完成了绘图形状的选择的设置。 基于平时课外上机实验的练习,对菜单的创建,command消息处理函数和 update_command_ui消息函数的添加过程比较熟练,这部分还算简单。难的是代码的添加,对绘制图形的程序有大概的思路,但具体编写时变量的运用以及函数的调用设置。这次实验中关键就是确定画图起点及终点坐标,因为是用鼠标绘制图形,所以需用函数来捕获鼠标当前所在位置的坐标,因此我设置了onlbuttondown()函数来捕获起点坐标,onmousemove()函数来捕获鼠标移动是的当前位置坐标,onlbuttonup()函数来捕获终点坐标。而绘制图形使用的函数是onpaint(),将图形的起点和终点坐标和鼠标的位置坐标相联系后就能用鼠标来绘制图形了,所以在它们之间用opoint和cpoint两变量实现链接。另外我觉得将绘图语句集中在onpaint()函数中,然后其他函数来调用onpaint()函数,这样不容易引起混乱,同时程序更简单,更有条理,便于修改。这次课程设计虽只是做了一个极其简单的绘图工具的制作,但也让我从设计者的角度看到了设计程序以及电脑软件工具的实质及难度,看似一个很简单的工具,其制作的背后工作是很大的,不光是图标,按钮的设置,程序的编写,代码的实现都是很精密且不容许一点错误的工作。平时我们使用的很顺手的一个小小工具,其开发的各项小号都不可小觑,由此,我们需要学的东西还太多太多。5. 参考文献csdn 朱志强6 测试结果1)点击链接,编译,运行后的窗口所示。7 主要代码 / drawview.cpp : implementation of the cdrawview class/#include stdafx.h#include draw.h#include drawdoc.h#include drawview.h#ifdef _debug#define new debug_new#undef this_filestatic char this_file = _file_;#endif/ cdrawviewimplement_dyncreate(cdrawview, cview)begin_message_map(cdrawview, cview)/afx_msg_map(cdrawview)on_command(id_draw_ellipse, ondrawellipse)on_command(id_draw_rectangle, ondrawrectangle)on_command(id_draw_sketch, ondrawsketch)on_wm_lbuttondown()on_wm_lbuttonup()on_wm_mousemove()on_update_command_ui(id_draw_ellipse, onupdatedrawellipse)on_update_command_ui(id_draw_rectangle, onupdatedrawrectangle)on_update_command_ui(id_draw_sketch, onupdatedrawsketch)/afx_msg_map/ standard printing commandson_command(id_file_print, cview:onfileprint)on_command(id_file_print_direct, cview:onfileprint)on_command(id_file_print_preview, cview:onfileprintpreview)end_message_map()/ cdrawview construction/destructioncdrawview:cdrawview()/ todo: add construction code herecdrawapp theapp;/ cdrawapp initializationbool cdrawapp:initinstance()afxenablecontrolcontainer();/ standard initialization/ if you are not using these features and wish to reduce the size/ of your final executable, you should remove from the following/ the specific initialization routines you do not need.#ifdef _afxdllenable3dcontrols();/ call this when using mfc in a shared dll#elseenable3dcontrolsstatic();/ call this when linking to mfc statically#endif/ change the registry key under which our settings are stored./ todo: you should modify this string to be something appropriate/ such as the name of your company or organization.setregistrykey(_t(local appwizard-generated applications);loadstdprofilesettings(); / load standard ini file options (including mru)/ register the applications document templates. document templates/ serve as the connection between documents, frame windows and views.csingledoctemplate* pdoctemplate;pdoctemplate = new csingledoctemplate(idr_mainframe,runtime_class(cdrawdoc),runtime_class(cmainframe), / main sdi frame windowruntime_class(cdrawview);adddoctemplate(pdoctemplate);/ parse command line for standard shell commands, dde, file openccommandlineinfo cmdinfo;parsecommandline(cmdinfo);/ dispatch commands specified on the command lineif (!processshellcommand(cmdinfo)return false;/ the one and only window has been initialized, so show and update it.m_pmainwnd-showwindow(sw_show);m_pmainwnd-updatewindow();return true;/ caboutdlg dialog used for app aboutclass caboutdlg : public cdialogpublic:caboutdlg();/ dialog data/afx_data(caboutdlg)enum idd = idd_aboutbox ;/afx_data/ classwizard generated virtual function overrides/afx_virtual(caboutdlg)protected:virtual void dodataexchange(cdataexchange* pdx); / ddx/ddv support/afx_virtual/ implementationprotected:/afx_msg(caboutdlg)/ no message handlers/afx_msgdeclare_message_map();caboutdlg:caboutdlg() : cdialog(caboutdlg:idd)/afx_data_init(caboutdlg)/afx_data_initvoid caboutdlg:dodataexchange(cdataexchange* pdx)cdialog:dodataexchange(pdx);/afx_data_map(caboutdlg)/afx_data_mapbegin_message_map(caboutdlg, cdialog)/afx_msg_map(caboutdlg)/ no message handlers/afx_msg_mapend_message_map()/ app command to run the dialogvoid cdrawapp:onappabout()caboutdlg aboutdlg;aboutdlg.domodal();/ cdrawapp message handlers/ drawdoc.cpp : implementation of the cdrawdoc class/#include stdafx.h#include draw.h#include drawdoc.h#ifdef _debug#define new debug_new#undef this_filestatic char this_file = _file_;#endif/ cdrawdocimplement_dyncreate(cdrawdoc, cdocument)begin_message_map(cdrawdoc, cdocument)/afx_msg_map(cdrawdoc)/ note - the classwizard will add and remove mapping macros here./ do not edit what you see in these blocks of generated code!/afx_msg_mapend_message_map()/ cdrawdoc construction/destructioncdrawdoc:cdrawdoc()/ todo: add one-time construction code herecdrawdoc:cdrawdoc()bool cdrawdoc:onnewdocument()if (!cdocument:onnewdocument()return false;/ todo: add reinitialization code here/ (sdi documents will reuse this document)return true;/ cdrawdoc serializationvoid cdrawdoc:serialize(carchive& ar)if (ar.isstoring()/ todo: add storing code hereelse/ todo: add loading code here/ cdrawdoc diagnostics#ifdef _debugvoid cdrawdoc:assertvalid() constcdocument:assertvalid();void cdrawdoc:dump(cdumpcontext& dc) constcdocument:dump(dc);#endif /_debug/ cdrawdoc commands/ mainfrm.cpp : implementation of the cmainframe class/#include stdafx.h#include draw.h#include mainfrm.h#ifdef _debug#define new debug_new#undef this_filestatic char this_file = _file_;#endif/ cmainframeimplement_dyncreate(cmainframe, cframewnd)begin_message_map(cmainframe, cframewnd)/afx_msg_map(cmainframe)/ note - the classwizard will add and remove mapping macros here./ do not edit what you see in these blocks of generated code !on_wm_create()/afx_msg_mapend_message_map()static uint indicators =id_separator, / status line indicatorid_indicator_caps,id_indicator_num,id_indicator_scrl,;/ cmainframe construction/destructioncmainframe:cmainframe()/ todo: add member initialization code herecmainframe:cmainframe()int cmainframe:oncreate(lpcreatestruct lpcreatestruct)if (cframewnd:oncreate(lpcreatestruct) = -1)return -1;if (!m_wndtoolbar.createex(this, tbstyle_flat, ws_child | ws_visible | cbrs_top| cbrs_gripper | cbrs_tooltips | cbrs_flyby | cbrs_size_dynamic) |!m_wndtoolbar.loadtoolbar(idr_mainframe)

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论