簡單畫圖板設計報告.doc_第1頁
簡單畫圖板設計報告.doc_第2頁
簡單畫圖板設計報告.doc_第3頁
簡單畫圖板設計報告.doc_第4頁
簡單畫圖板設計報告.doc_第5頁
已閱讀5頁,還剩21頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領

文檔簡介

簡單畫圖板設計報告1. 設計目的:設計一個能夠自定義顏色;能夠實現(xiàn)自定義字體的大小顏色并且輸出到畫圖板上;能夠實現(xiàn)簡單的圖形繪制(如:直線;矩形;橢圓;圓角矩形等);能夠實現(xiàn)鉛筆功能來實現(xiàn)連續(xù)畫線;能夠實現(xiàn)自定義線寬和自定義線型;能夠實現(xiàn)畫刷和局部填充顏色;能夠實現(xiàn)實現(xiàn)清屏功能和計時的附加功能。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測試過程:先進行了基本圖形的繪制,然后測試圖形的顏色,線寬,線型,畫刷填充,文字顯示,位圖載入,上述功能基本都能實現(xiàn)。最后測試清屏,橡皮圖形重繪等功能,遇到了一些問題。測試遇到問題:1.窗口不能重繪。2.清屏后不能重繪。解決問題方法:1.在OnDraw函數(shù)中加入一個Point數(shù)組,把已經(jīng)畫過的保存起來。 2.將畫圖選擇變量select設-1,調用Invalidate();這樣在清屏后還可調用OnDraw函數(shù)進行畫圖。5源程序清單和執(zhí)行結果: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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論