您好,欢迎访问三七文档
当前位置:首页 > 建筑/环境 > 工程监理 > 简易画图板的设计与实现
专业课程设计(2011/2012学年第2学期)题目一:简易画图板的设计与实现专业计算机通信学生姓名班级学号09002736指导教师王海艳指导单位计算机学院·计算机科学与技术系日期2012年6月20日教师评语教师签名:年月日一、课题名称设计题目1:简易画图板的设计与实现二、课题内容和要求利用MFC完成画图板的基本功能。此程序将实现简单的绘图功能,包括点、直线、矩形、椭圆、扇形和连续线的绘制。并且能实现绘图的控制,包括线宽、线型和颜色的设置,图形的保存和打开以及笔刷的使用。三、需求分析1)在单文档菜单中,在菜单行中可插入一个菜单项,命名为绘图,在下拉菜单中可分别设置绘制的图形形状,如直线、矩形及椭圆,线宽选项,有1-5可供选择,还可以设置线色以及填充色,通过弹出的颜色对话框选择需要的颜色,如果不选择线宽、线色以及填充色,则按默认的画笔,画刷来绘制选择的图形。2)选择好图形后,通过鼠标可以绘制出相应的直线,矩形或椭圆,鼠标的按下确定图形的起点,鼠标的拖动则确定了图形的终点,即通过鼠标的拖动来决定图形的大小,当鼠标弹起,此图形则绘制完毕。3)增添工具栏,设置绘制的图形形状,线色以及填充色,可更方便地选择相应的功能。成绩评定备注四、概要设计1)对需要用到的变量进行初始化。2)选择相应的图形之后就响应相应的消息处理函数,给shape赋对应的值。选择不同的线宽,线色与填充色,即可改变画笔或画刷的属性。3)鼠标的按下响应函数OnLButtonDown(),捕捉鼠标当前位置得到起点的坐标,鼠标的拖动响函数OnMouseMove()改变终点的坐标,鼠标的弹起响应OnLButtonUp(),确定终点坐标,刷新,得到绘制图形。4)选择图形或其它属性,可进行下一次绘制。开始定义并初始化变shape线色m_ncolor填充色m_fcolor画笔pen画刷brush绘图起点opoint绘图终点cpoint选择线宽改变画笔属性默认值(w=1)改变画刷属性默认值(黑色)默认值(黑色)选择填充色改变画笔属性选择线色图1程序流程图五、详细设计1)创建单文档2)编辑菜单3)创建工具栏4)在相应消息函数处添加代码,实现其功能5)选择要绘制的图形6)改变线宽7)改变线色8)绘制图形9)关键代码//GraphicView.cpp:implementationoftheCGraphicViewclass//矩形鼠标左键按下响应函数OnLButtonDown()opoint=point直线鼠标左键弹起响应函数OnLButtonUp()刷新,得到图形鼠标移动响应函数OnMouseMove()epoint=point响应OnPaint(),绘制图形响应函数OnEllipse()shape=3响应函数OnRect()shape=2响应函数OnLine()shape=1椭圆结束#includestdafx.h#includeGraphic.h#includeGraphicDoc.h#includeGraphicView.h#includeSettingDlg.h#ifdef_DEBUG#definenewDEBUG_NEW#undefTHIS_FILEstaticcharTHIS_FILE[]=__FILE__;#endif///////////////////////////////////////////////////////////////////////////////CGraphicViewIMPLEMENT_DYNCREATE(CGraphicView,CView)BEGIN_MESSAGE_MAP(CGraphicView,CView)//{{AFX_MSG_MAP(CGraphicView)ON_COMMAND(IDM_DOT,OnDot)ON_COMMAND(IDM_ELL,OnEll)ON_COMMAND(IDM_LINE,OnLine)ON_COMMAND(IDM_RECT,OnRect)ON_WM_LBUTTONDOWN()ON_WM_LBUTTONUP()ON_COMMAND(IDM_SETTING,OnSetting)ON_COMMAND(IDM_COLOR,OnColor)ON_WM_MOUSEMOVE()//}}AFX_MSG_MAP//StandardprintingcommandsON_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()///////////////////////////////////////////////////////////////////////////////CGraphicViewconstruction/destructionCGraphicView::CGraphicView(){//TODO:addconstructioncodeherem_nDrawType=0;m_ptOrigin=0;m_nLineWidth=1;m_nLineStyle=0;m_clr=RGB(0,0,0);m_bDrawing=0;}CGraphicView::~CGraphicView(){}BOOLCGraphicView::PreCreateWindow(CREATESTRUCT&cs){//TODO:ModifytheWindowclassorstylesherebymodifying//theCREATESTRUCTcscs.lpszClass=AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW,LoadCursor(NULL,IDC_CROSS),(HBRUSH)GetStockObject(BLACK_BRUSH),0);returnCView::PreCreateWindow(cs);}///////////////////////////////////////////////////////////////////////////////CGraphicViewdrawingvoidCGraphicView::OnDraw(CDC*pDC){CGraphicDoc*pDoc=GetDocument();ASSERT_VALID(pDoc);//TODO:adddrawcodefornativedatahere}///////////////////////////////////////////////////////////////////////////////CGraphicViewprintingBOOLCGraphicView::OnPreparePrinting(CPrintInfo*pInfo){//defaultpreparationreturnDoPreparePrinting(pInfo);}voidCGraphicView::OnBeginPrinting(CDC*/*pDC*/,CPrintInfo*/*pInfo*/){//TODO:addextrainitializationbeforeprinting}voidCGraphicView::OnEndPrinting(CDC*/*pDC*/,CPrintInfo*/*pInfo*/){//TODO:addcleanupafterprinting}///////////////////////////////////////////////////////////////////////////////CGraphicViewdiagnostics#ifdef_DEBUGvoidCGraphicView::AssertValid()const{CView::AssertValid();}voidCGraphicView::Dump(CDumpContext&dc)const{CView::Dump(dc);}CGraphicDoc*CGraphicView::GetDocument()//non-debugversionisinline{ASSERT(m_pDocument-IsKindOf(RUNTIME_CLASS(CGraphicDoc)));return(CGraphicDoc*)m_pDocument;}#endif//_DEBUG///////////////////////////////////////////////////////////////////////////////CGraphicViewmessagehandlersvoidCGraphicView::OnDot(){//TODO:Addyourcommandhandlercodeherem_nDrawType=1;}voidCGraphicView::OnEll(){//TODO:Addyourcommandhandlercodeherem_nDrawType=4;}voidCGraphicView::OnLine(){//TODO:Addyourcommandhandlercodeherem_nDrawType=2;}voidCGraphicView::OnRect(){//TODO:Addyourcommandhandlercodeherem_nDrawType=3;}voidCGraphicView::OnLButtonDown(UINTnFlags,CPointpoint){//TODO:Addyourmessagehandlercodehereand/orcalldefaultm_bDrawing=1;m_ptOrigin=point;m_ptTarget=point;CView::OnLButtonDown(nFlags,point);}voidCGraphicView::OnLButtonUp(UINTnFlags,CPointpoint){//TODO:Addyourmessagehandlercodehereand/orcalldefaultif(!m_bDrawing)return;m_bDrawing=0;CClientDCdc(this);CPenpen(m_nLineStyle,m_nLineWidth,m_clr);dc.SelectObject(&pen);CBrush*pBrush=CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH));dc.SelectObject(pBrush);switch(m_nDrawType){case1:dc.SetPixel(point,m_clr);break;case2:dc.MoveTo(m_ptOrigin);dc.LineTo(point);break;case3:dc.Rectangle(CRect(m_ptOrigin,point));break;case4:dc.Ellipse(CRect(m_ptOrigin,point));break;}CView::OnLButtonUp(nFlags,point);}voidCGraphicView::OnSetting(){//TODO:AddyourcommandhandlercodehereCSettingDlgdlg;dlg.m_nLineWidth=m_nLineWidth;dlg.m_nLineStyle=m_nLineStyle;dlg.m_clr=m_clr;if(IDOK==dlg.DoModal())m_nLineWidth=dlg.m_nLineWidth;m_nLineStyle=dlg.m_nLineStyle;}voi
本文标题:简易画图板的设计与实现
链接地址:https://www.777doc.com/doc-2724154 .html