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

下载本文档

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

文档简介

简单画图板设计报告1. 设计目的:设计一个能够自定义颜色;能够实现自定义字体的大小颜色并且输出到画图板上;能够实现简单的图形绘制(如:直线;矩形;椭圆;圆角矩形等);能够实现铅笔功能来实现连续画线;能够实现自定义线宽和自定义线型;能够实现画刷和局部填充颜色;能够实现实现清屏功能和计时的附加功能。2.总体设计:简单画图板图 形直线矩形椭圆铅笔画线圆角矩形饼图线宽线宽为2线宽为3线宽为5自定义线宽颜色红蓝绿自定义颜色线型自定义线型画刷文字调用文字附加功能清屏秒表3详细设计:CMyView 颜色类型:COLORREF; 线宽类型:int; 线型类型:int; 坐标点类型:CPOINT;输出字体类型:Cstring;void CMyView:OnDelete();void CMyView:OnDline();void CMyView:OnDraw(CDC* pDC);voidCMyView:OnEllipse();voidCMyView:OnFillcolor();voidCMyView:OnLButtonDown(UINTnFlags,Cpointpoint);voidCMyView:OnLButtonUp(UINT nFlags, CPoint point); void CMyView:OnLine();void CMyView:OnMouseMove(UINT nFlags, CPoint point);voidCMyView:OnMyfont();voidCMyView:OnPie();voidCMyView:OnRectangle();voidCMyView:OnRoundrectangle();voidCMyView:OnUserdefined();voidCMyView:OnUserdefinedbrush();voidCMyView:OnUserdifinedColor();voidCMyView:OnUserdifinedLinewidth();BOOL CMyView:PreCreateWindow(CREATESTRUCT& cs);MYFONT颜色类型:COLORREF;颜色列表:CListBox编辑框变量:Cstring类型选择列表:int;voidMYFONT:OnCancelMode();void MYFONT:OnChangeDataEdit();void MYFONT:OnExitButton();BOOL MYFONT:OnInitDialog();voidMYFONT:OnPaint();voidMYFONT:OnRadio();voidMYFONT:OnSetButton();CtimerDlg时间变量:int;时间变量m_nTimer:UINT;传递变量m_timer:Cstring;CTimerDlg:CTimerDlg(CWnd*pParent )CDialog(CTimerDlg:IDD, pParent); void CTimerDlg:DoDataExchange(CDataExchange* pDX); void CTimerDlg:OnBeginTime();voidCTimerDlg:OnCancle();void CTimerDlg:OnEndTime();voidCTimerDlg:OnTimer(UINTnIDEvent);父类ClineWidthCLineWidth:CLineWidth(CWnd* pParent)CDialog(CLineWidth:IDD, pParent);voidCLineWidth:DoDataExchange(CDataExchange*pDX);voidCLineWidth:OnOK;ClineStyleCLineStyle:CLineStyle(CWnd* pParent)CDialog(CLineStyle:IDD, pParent);voidCLineStyle:DoDataExchange(CDataExchange*pDX);voidCLineStyle:OnCancel();voidCLineStyle:OnLinestyle();void CLineStyle:OnOK();4测试过程:先进行了基本图形的绘制,然后测试图形的颜色,线宽,线型,画刷填充,文字显示,位图载入,上述功能基本都能实现。最后测试清屏,橡皮图形重绘等功能,遇到了一些问题。测试遇到问题:1.窗口不能重绘。2.清屏后不能重绘。解决问题方法:1.在OnDraw函数中加入一个Point数组,把已经画过的保存起来。 2.将画图选择变量select设-1,调用Invalidate();这样在清屏后还可调用OnDraw函数进行画图。5源程序清单和执行结果:1我的画图板加强版.cpp:#include stdafx.h#include 我的画图板加强版.h#include MainFrm.h#include 我的画图板加强版Doc.h#include 我的画图板加强版View.h#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE = _FILE_;#endif/ CMyAppBEGIN_MESSAGE_MAP(CMyApp, CWinApp)/AFX_MSG_MAP(CMyApp)ON_COMMAND(ID_APP_ABOUT, OnAppAbout)/ NOTE - the ClassWizard will add and remove mapping macros here./ DO NOT EDIT what you see in these blocks of generated code!/AFX_MSG_MAP/ Standard file based document commandsON_COMMAND(ID_FILE_NEW, CWinApp:OnFileNew)ON_COMMAND(ID_FILE_OPEN, CWinApp:OnFileOpen)/ Standard print setup commandON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp:OnFilePrintSetup)END_MESSAGE_MAP()/ CMyApp constructionCMyApp:CMyApp()/ TODO: add construction code here,/ Place all significant initialization in InitInstance/ The one and only CMyApp objectCMyApp theApp;/ CMyApp initializationBOOL CMyApp: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(CMyDoc),RUNTIME_CLASS(CMainFrame), / main SDI frame windowRUNTIME_CLASS(CMyView);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();m_pMainWnd-SetWindowText(软工二班尹异倾情打造);/输出窗口的名称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 CMyApp:OnAppAbout()CAboutDlg aboutDlg;aboutDlg.DoModal();/ CMyApp message handlers2 我的画图板加强版View.cpp#include stdafx.h#include 我的画图板加强版.h#include 我的画图板加强版Doc.h#include 我的画图板加强版View.h#include LineWidth.h#include MYFONT.h#includeLineStyle.h#includeBrushStyle.h#includeMainFrm.h#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE = _FILE_;#endifextern int linewidth;extern int linestyle;/ CMyViewIMPLEMENT_DYNCREATE(CMyView, CView)BEGIN_MESSAGE_MAP(CMyView, CView)/AFX_MSG_MAP(CMyView)ON_COMMAND(ID_LINE, OnLine)ON_COMMAND(ID_RECTANGLE, OnRectangle)ON_COMMAND(ID_ELLIPSE, OnEllipse)ON_COMMAND(ID_LINEWIDTH_TWO, OnLinewidthTwo)ON_COMMAND(ID_LINEWIDTH_THREE, OnLinewidthThree)ON_COMMAND(ID_LINEWIDTH_FIVE, OnLinewidthFive)ON_WM_LBUTTONDOWN()ON_WM_LBUTTONUP()ON_COMMAND(ID_RED_COLOR, OnRedColor)ON_COMMAND(ID_BULE_COLOR, OnBuleColor)ON_COMMAND(ID_GREEN_COLOR, OnGreenColor)ON_COMMAND(ID_USERDIFINED_COLOR, OnUserdifinedColor)ON_COMMAND(ID_USERDIFINED_LINEWIDTH, OnUserdifinedLinewidth)ON_COMMAND(ID_MYFONT, OnMyfont)ON_COMMAND(ID_USERDEFINED, OnUserdefined)ON_WM_MOUSEMOVE()ON_COMMAND(ID_DLINE, OnDline)ON_COMMAND(ID_USERDEFINEDBRUSH, OnUserdefinedbrush)ON_COMMAND(ID_ROUNDRECTANGLE, OnRoundrectangle)ON_COMMAND(ID_PIE, OnPie)ON_COMMAND(ID_DELETE, OnDelete)ON_COMMAND(ID_FILLCOLOR, OnFillcolor)/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()/ CMyView construction/destructionCMyView:CMyView() lw=1; r=0; g=0; b=0; tag=false; loop=1;/ TODO: add construction code here m_clean= false;CMyView:CMyView()BOOL CMyView:PreCreateWindow(CREATESTRUCT& cs)/ TODO: Modify the Window class or styles here by modifying/ the CREATESTRUCT csreturn CView:PreCreateWindow(cs);/ CMyView drawingvoid CMyView:OnDraw(CDC* pDC)CMyDoc* pDoc = GetDocument();ASSERT_VALID(pDoc);if (!m_clean)/m_clean是一个标志判断是否清空屏幕。if(loop=1)/loop 是一个标志判断为画笔还是画刷。CPen Pen; Pen.CreatePen(m_linestyle,lw,(m_color); CPen *pOldPen = pDC-SelectObject(&Pen); if(flag=1)/画线。 pDC-MoveTo(start); pDC-LineTo(end);else if(flag=2)/画矩形pDC-Rectangle(start.x,start.y,end.x,end.y);else if(flag=3)/画椭圆 pDC-Ellipse(start.x,start.y,end.x,end.y);if(flag=4)/铅笔画线pDC-MoveTo(start1); pDC-LineTo(end1);if(flag=5)/画圆角矩形pDC-RoundRect(start.x,start.y,end.x,end.y,25,25);if(flag=6)/画饼图pDC-Pie(start.x,start.y,end.x,end.y,100,200,300,400);if(flag=7)填充色彩CBrush brush; brush.CreateSolidBrush(m_color); CBrush *poldbrush=pDC-SelectObject(&brush); pDC-FloodFill(start.x,start.y,m_color); pDC-SelectObject(brush);if(flag=8)/输出文本框 CFont myFont;myFont.CreateFont(8+ 8*m_size, 0, 0, 0 ,400,FALSE, FALSE, 0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH|FF_SWISS,Arial);CFont* pOldFont = pDC-SelectObject(&myFont);pDC-SetBkMode(TRANSPARENT);pDC-SetTextColor(m_color);pDC-TextOut(start.x,start.y,m_text);DeleteObject(Pen);else if(loop=2)/ 实用画刷CBrush Br; Br.CreateSolidBrush(m_color); pDC-SelectObject(&Br); if(flag=1) pDC-MoveTo(start); pDC-LineTo(end);else if(flag=2)/填充矩形pDC-Rectangle(start.x,start.y,end.x,end.y);else if(flag=3)/填充椭圆 pDC-Ellipse(start.x,start.y,end.x,end.y);if(flag=5)/填充圆角矩形pDC-RoundRect(start.x,start.y,end.x,end.y,25,25);if(flag=6)/填充饼图pDC-Pie(start.x,start.y,end.x,end.y,100,200,300,400);if(flag=7)/填充颜色CBrush brush; brush.CreateSolidBrush(m_color);CBrush *poldbrush=pDC-SelectObject(&brush); pDC-FloodFill(start.x,start.y,m_color); pDC-SelectObject(poldbrush);DeleteObject(Br);/ TODO: add draw code for native data herem_clean = false;/ CMyView printingBOOL CMyView:OnPreparePrinting(CPrintInfo* pInfo)/ default preparationreturn DoPreparePrinting(pInfo);void CMyView:OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)/ TODO: add extra initialization before printingvoid CMyView:OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)/ TODO: add cleanup after printing/ CMyView diagnostics#ifdef _DEBUGvoid CMyView:AssertValid() constCView:AssertValid();void CMyView:Dump(CDumpContext& dc) constCView:Dump(dc);CMyDoc* CMyView:GetDocument() / non-debug version is inlineASSERT(m_pDocument-IsKindOf(RUNTIME_CLASS(CMyDoc);return (CMyDoc*)m_pDocument;#endif /_DEBUG/ CMyView message handlersvoid CMyView:OnLine() flag=1; / TODO: Add your command handler code herevoid CMyView:OnRectangle() flag=2;/ TODO: Add your command handler code herevoid CMyView:OnEllipse() flag=3;/ TODO: Add your command handler code herevoid CMyView:OnLinewidthTwo() lw=2;/ TODO: Add your command handler code herevoid CMyView:OnLinewidthThree() lw=3;/ TODO: Add your command handler code herevoid CMyView:OnLinewidthFive() lw=5;/ TODO: Add your command handler code herevoid CMyView:OnLButtonDown(UINT nFlags, CPoint point) start=point;/ TODO: Add your message handler code here and/or call defaultstart1=point;start2=start1;CView:OnLButtonDown(nFlags, point);tag=true;void CMyView:OnLButtonUp(UINT nFlags, CPoint point) end=point; Invalidate(false);/ TODO: Add your message handler code here and/or call defaulttag=false;ReleaseCapture();CView:OnLButtonUp(nFlags, point);Invalidate(false);void CMyView:OnRedColor() m_color=RGB(255,0,0);/ TODO: Add your command handler code herevoid CMyView:OnBuleColor() m_color=RGB(0,0,255);/ TODO: Add your command handler code herevoid CMyView:OnGreenColor() m_color=RGB(0,255,0);/ TODO: Add your command handler code herevoid CMyView:OnUserdifinedColor() / TODO: Add your command handler code hereCColorDialog dlg;if(IDOK=dlg.DoModal() m_color = dlg.GetColor();void CMyView:OnUserdifinedLinewidth() / TODO: Add your command handler code hereCLineWidth dlg;dlg.DoModal();lw=linewidth;void CMyView:OnMyfont() flag=8; MYFONT dlg; dlg.DoModal(); m_color = dlg.m_Color; m_text=dlg.m_DataEdit; m_size=dlg.m_Size;/ TODO: Add your command handler code herevoid CMyView:OnUserdefined() CLineStyle dlg; dlg.DoModal(); m_linestyle=linestyle;/ TODO: Add your command handler code herevoid CMyView:OnMouseMove(UINT nFlags, CPoint point) / TODO: Add your message handler code here and/or call defaultCMainFrame* pFrame=(CMainFrame*) AfxGetMainWnd();CStatusBar* pStatusBar=(CStatusBar*) pFrame-GetDescendantWindow(AFX_IDW_STATUS_BAR);CString strMousePoint; strMousePoint.Format(%3d,%3d,point.x,point.y); pStatusBar-SetPaneText( pStatusBar-CommandToIndex(IDS_MOUSE_POINT),strMousePoint);if(tag)SetCapture();start1=start2;end1=point;start2=end1; Invalidate(false);CView:OnMouseMove(nFlags, point);void CMyView:OnDline() / TODO: Add your command handler code hereflag=4;void CMyView:OnUserdefinedbrush() loop=2;/ TODO: Add your command handler code herevoid CMyView:OnRoundrectangle() flag=5;/ TODO: Add your command handler code herevoid CMyView:OnPie() flag=6; /TODO: Add your command handler code herevoid CMyView:OnDelete() / TODO: Add your command handler code herem_clean = true;RedrawWindow();void CMyView:OnFillcolor() flag=7;/ TODO: Add your command handler code here3 LineStyle.cpp#include stdafx.h#include 我的画图板加强版.h#include LineStyle.h#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE = _FILE_;#endifextern int linestyle;/ CLineStyle dialogCLineStyle:CLineStyle(CWnd* pParent /*=NULL*/): CDialog(CLineStyle:IDD, pParent)/AFX_DATA_INIT(CLineStyle) m_userdefined=0;/ NOTE: the ClassWizard will add member initialization here/AFX_DATA_INITvoid CLineStyle:DoDataExchange(CDataExchange* pDX)CDialog:DoDataExchange(pDX);/AFX_DATA_MAP(CLineStyle)/ NOTE: the ClassWizard will add DDX and DDV calls here/AFX_DATA_MAPBEGIN_MESSAGE_MAP(CLineStyle, CDialog)/AFX_MSG_MAP(CLineStyle)ON_BN_CLICKED(IDC_LINESTYLE0, OnLinestyle0)ON_BN_CLICKED(IDC_LINESTYLE1, OnLinestyle1)ON_BN_CLICKED(IDC_LINESTYLE2, OnLinestyle2)/AFX_MSG_MAPEND_MESSAGE_MAP()/ CLineStyle message handlersvoid CLineStyle:OnOK() / TODO: Add extra validation hereCDialog:OnOK();void CLineStyle:OnCancel() / TODO: Add extra cleanup hereCDialog:OnCancel();void CLineStyle:OnLinestyle0() linestyle=1;Invalidate();/ TODO: Add your control notification handler code herevoid CLineStyle:OnLinestyle1() linestyle=2;Invalidate();/ TODO: Add your control notification handler code herevoid CLineStyle:OnLinestyle2() linestyle=0;Invalidate();/ TODO: Add your control notification handler code here4 LineWidth.cpp#include stdafx.h#include 我的画图板加强版.h#include LineWidth.h#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE = _FILE_;#endifextern int linewidth;/ CLineWidth dialogCLineWidth:CLineWidth(CWnd* pParent /*=NULL*/): CDialog(CLineWidth:IDD, pParent)/AFX_DATA_INIT(CLineWidth)m_linewidth = 0;/AFX_DATA_INITvoid CLineWidth:DoDataExchange(CDataExchange* pDX)CDialog:DoDataExchange(pDX);/AFX_DATA_MAP(CLineWidth)DDX_Text(pDX, IDC_EDIT1, m_linewidth);/AFX_DATA_MAPBEGIN_MESSAGE_MAP(CLineWidth, CDialog)/AFX_MSG_MAP(CLineWidth)/AFX_MSG_MAPEND_MESSAGE_MAP()/ CLineWidth message handlersvoid CLineWidth:OnOK() / TODO: Add extra validation hereUpdateData(true);linewidth=m_linewidth;CDialog:OnOK();5MYFONT.cpp#include stdafx.h#include 我的画图板加强版.h#include MYFONT.h#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE = _FILE_;#endif / MYFON

温馨提示

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

评论

0/150

提交评论