




免费预览已结束,剩余1页可下载查看
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
绘图程序代码文档类:(1). class CDrawDoc : public CDocument public: /定义数据成员COLORREF m_color; /颜色CRect m_rectGraph; /矩形CPoint m_OldPoint,m_NewPoint,m_LastPoint; /直线int m_nType; /选择的画法类型CPoint m_Curve1000; /随手画int m_nCurveCount;(2). BOOL CDrawDoc:OnNewDocument() /文档类中初始化变量if (!CDocument:OnNewDocument()return FALSE;/ TODO: add reinitialization code here/ (SDI documents will reuse this document)m_color=RGB(0,0,0);m_rectGraph=CRect(0,0,0,0);m_nType=1;m_nCurveCount=0;return TRUE;(3). void CDrawDoc:Serialize(CArchive& ar) /文档类的序列化函数为保存和读出代码if (ar.IsStoring()/ TODO: add storing code herearm_color;arm_LastPoint;arm_NewPoint;arm_nType;arm_OldPoint;arm_nCurveCount;arm_rectGraph;for(int i=0;im_nCurveCount;i+)arm_color;arm_LastPoint;arm_NewPoint;arm_nType;arm_OldPoint;arm_nCurveCount;arm_rectGraph;for(int i=0;im_Curvei;视图类:(4). class CDrawView : public CViewprivate:BOOL m_bCaptured; /捕捉标志/自定义的刷新函数,用于调整矩形的坐标,确保矩形的第二对坐标参数大于第一对 void MyInvalidateRect(CRect rect,BOOL bErase=TRUE);(5). CDrawView:CDrawView() /视图类构造函数初始化变量/ TODO: add construction code herem_bCaptured=FALSE;(6). void CDrawView:OnDraw(CDC* pDC) /绘图CDrawDoc* pDoc = GetDocument();ASSERT_VALID(pDoc);/ TODO: add draw code for native data hereCPen newPen,*oldPen;newPen.CreatePen(PS_SOLID,1,pDoc-m_color); /创建选定颜色的绘图笔oldPen=pDC-SelectObject(&newPen);switch(pDoc-m_nType)case 1: /画直线pDC-MoveTo(pDoc-m_OldPoint);pDC-LineTo(pDoc-m_NewPoint);break;case 2: /绘制矩形pDC-Rectangle(pDoc-m_rectGraph);break;case 3: /绘制圆pDC-Ellipse(pDoc-m_rectGraph);break;case 4: /绘制随手画if(pDoc-m_nCurveCount0)pDC-MoveTo(pDoc-m_Curve0);for(int j=1;jm_nCurveCount;j+)pDC-LineTo(pDoc-m_Curvej);break;pDC-SelectObject(oldPen);菜单消息处理函数:(7). void CDrawView:OnSelectEllipse() /与画圆子菜单对应的消息处理函数/ TODO: Add your command handler code hereCDrawDoc* pDoc=GetDocument();ASSERT_VALID(pDoc);pDoc-m_nType=3;void CDrawView:OnUpdateSelectEllipse(CCmdUI* pCmdUI) /修改画圆子菜单对应的消息处理函数/ TODO: Add your command update UI handler code hereCDrawDoc* pDoc=GetDocument();ASSERT_VALID(pDoc);pCmdUI-SetCheck(pDoc-m_nType=3);void CDrawView:OnSelectFree() /与随手画子菜单对应的消息处理函数/ TODO: Add your command handler code hereCDrawDoc* pDoc=GetDocument();ASSERT_VALID(pDoc);pDoc-m_nType=4;void CDrawView:OnUpdateSelectFree(CCmdUI* pCmdUI)/修改随手画子菜单对应的消息处理函数 / TODO: Add your command update UI handler code hereCDrawDoc* pDoc=GetDocument();ASSERT_VALID(pDoc);pCmdUI-SetCheck(pDoc-m_nType=4);void CDrawView:OnSelectLine()/与画线子菜单对应的消息处理函数 / TODO: Add your command handler code hereCDrawDoc* pDoc=GetDocument();ASSERT_VALID(pDoc);pDoc-m_nType=1;void CDrawView:OnUpdateSelectLine(CCmdUI* pCmdUI)/修改画线子菜单对应的消息处理函数 / TODO: Add your command update UI handler code hereCDrawDoc* pDoc=GetDocument();ASSERT_VALID(pDoc);pCmdUI-SetCheck(pDoc-m_nType=1);void CDrawView:OnSelectRect()/与画矩形子菜单对应的消息处理函数 / TODO: Add your command handler code hereCDrawDoc* pDoc=GetDocument();ASSERT_VALID(pDoc);pDoc-m_nType=2;void CDrawView:OnUpdateSelectRect(CCmdUI* pCmdUI)/修改画矩形子菜单对应的消息处理函数 / TODO: Add your command update UI handler code hereCDrawDoc* pDoc=GetDocument();ASSERT_VALID(pDoc);pCmdUI-SetCheck(pDoc-m_nType=2);void CDrawView:OnColor() /显示颜色对话框处理函数/ TODO: Add your command handler code hereCDrawDoc* pDoc=GetDocument();ASSERT_VALID(pDoc);CColorDialog dlg;if(dlg.DoModal()=IDOK)pDoc-m_color=dlg.GetColor(); /取颜色对话框颜色鼠标消息处理函数:(8). void CDrawView:OnLButtonDown(UINT nFlags, CPoint point) /鼠标按下消息处理函数 / TODO: Add your message handler code here and/or call defaultCDrawDoc* pDoc=GetDocument();ASSERT_VALID(pDoc);if(pDoc-m_nType=1&pDoc-m_nTypem_OldPoint=point; /取画线起始点、续点、区域pDoc-m_NewPoint=point;pDoc-m_rectGraph=CRect(point,point); if(pDoc-m_nType=4)pDoc-m_Curve0=point; /随手画的第一个点pDoc-m_nCurveCount=1; /随手画的所有点计数Invalidate();CView:OnLButtonDown(nFlags, point);void CDrawView:OnMouseMove(UINT nFlags, CPoint point)/鼠标移动消息处理函数 / TODO: Add your message handler code here and/or call defaultCDrawDoc* pDoc=GetDocument();ASSERT_VALID(pDoc);if(m_bCaptured)if(pDoc-m_nType=1&pDoc-m_nTypem_rectGraph);pDoc-m_rectGraph=CRect(pDoc-m_OldPoint,point);pDoc-m_NewPoint=point;InvalidateRect(pDoc-m_rectGraph);elseif(pDoc-m_nCurveCountm_OldPoint=pDoc-m_NewPoint;pDoc-m_NewPoint=point;pDoc-m_rectGraph=CRect(pDoc-m_OldPoint,pDoc-m_NewPoint);pDoc-m_CurvepDoc-m_nCurveCount=point;pDoc-m_nCurveCount+;InvalidateRect(pDoc-m_rectGraph);CView:OnMouse
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2024年秋九年级历史上册 第3课《古代印度》说课稿 中图版
- 《喝牛奶问题》教学设计五年级下册数学人教版
- 2025年特殊护理员考试内容题库及答案
- 2025年内科护理案例及答案题库及答案
- 求职课件教学课件
- Tauroallolithocholanoic-acid-sodium-生命科学试剂-MCE
- Synuclein-alpha-Lys-13C6-15N2-生命科学试剂-MCE
- Silane-1a-3b-5E-7E-22E-9-10-secoergosta-5-7-10-19-22-tetraene-1-3-diyl-bis-oxy-bis-1-1-dimethylethyl-dimethyl-生命科学试剂-MCE
- sEH-IN-3-生命科学试剂-MCE
- 疫情消毒水防疫知识培训课件
- 超声引导下置管技术规范与临床应用
- 大阪驾照考试题库及答案
- 2025版心肺复苏术指南
- 2025至2030中国电动机制造市场需求趋势及前景运行状况分析报告
- 取样员考试试题及答案
- 2025年湖南省中考地理试卷真题(含答案)
- 汽修店考核管理制度
- 公司社会责任管理制度
- 2025年中国智慧教育白皮书
- T/CECS 10011-2022聚乙烯共混聚氯乙烯高性能双壁波纹管材
- DB32/ 4439-2022工业涂装工序大气污染物排放标准
评论
0/150
提交评论