简单画图板设计报告.docx
- 文档编号:6268574
- 上传时间:2023-01-05
- 格式:DOCX
- 页数:29
- 大小:209.46KB
简单画图板设计报告.docx
《简单画图板设计报告.docx》由会员分享,可在线阅读,更多相关《简单画图板设计报告.docx(29页珍藏版)》请在冰豆网上搜索。
简单画图板设计报告
简单画图板设计报告
1.设计目的:
设计一个能够自定义颜色;能够实现自定义字体的大小颜色并且输出到画图板上;能够实现简单的图形绘制(如:
直线;矩形;椭圆;圆角矩形等);能够实现铅笔功能来实现连续画线;能够实现自定义线宽和自定义线型;能够实现画刷和局部填充颜色;能够实现实现清屏功能和计时的附加功能。
2.总体设计:
3详细设计:
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
#definenewDEBUG_NEW
#undefTHIS_FILE
staticcharTHIS_FILE[]=__FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
//CMyApp
BEGIN_MESSAGE_MAP(CMyApp,CWinApp)
//{{AFX_MSG_MAP(CMyApp)
ON_COMMAND(ID_APP_ABOUT,OnAppAbout)
//NOTE-theClassWizardwilladdandremovemappingmacroshere.
//DONOTEDITwhatyouseeintheseblocksofgeneratedcode!
//}}AFX_MSG_MAP
//Standardfilebaseddocumentcommands
ON_COMMAND(ID_FILE_NEW,CWinApp:
:
OnFileNew)
ON_COMMAND(ID_FILE_OPEN,CWinApp:
:
OnFileOpen)
//Standardprintsetupcommand
ON_COMMAND(ID_FILE_PRINT_SETUP,CWinApp:
:
OnFilePrintSetup)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
//CMyAppconstruction
CMyApp:
:
CMyApp()
{
//TODO:
addconstructioncodehere,
//PlaceallsignificantinitializationinInitInstance
}
/////////////////////////////////////////////////////////////////////////////
//TheoneandonlyCMyAppobject
CMyApptheApp;
/////////////////////////////////////////////////////////////////////////////
//CMyAppinitialization
BOOLCMyApp:
:
InitInstance()
{
AfxEnableControlContainer();
//Standardinitialization
//Ifyouarenotusingthesefeaturesandwishtoreducethesize
//ofyourfinalexecutable,youshouldremovefromthefollowing
//thespecificinitializationroutinesyoudonotneed.
#ifdef_AFXDLL
Enable3dControls();//CallthiswhenusingMFCinasharedDLL
#else
Enable3dControlsStatic();//CallthiswhenlinkingtoMFCstatically
#endif
//Changetheregistrykeyunderwhichoursettingsarestored.
//TODO:
Youshouldmodifythisstringtobesomethingappropriate
//suchasthenameofyourcompanyororganization.
SetRegistryKey(_T("LocalAppWizard-GeneratedApplications"));
LoadStdProfileSettings();//LoadstandardINIfileoptions(includingMRU)
//Registertheapplication'sdocumenttemplates.Documenttemplates
//serveastheconnectionbetweendocuments,framewindowsandviews.
CSingleDocTemplate*pDocTemplate;
pDocTemplate=newCSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CMyDoc),
RUNTIME_CLASS(CMainFrame),//mainSDIframewindow
RUNTIME_CLASS(CMyView));
AddDocTemplate(pDocTemplate);
//Parsecommandlineforstandardshellcommands,DDE,fileopen
CCommandLineInfocmdInfo;
ParseCommandLine(cmdInfo);
//Dispatchcommandsspecifiedonthecommandline
if(!
ProcessShellCommand(cmdInfo))
returnFALSE;
//Theoneandonlywindowhasbeeninitialized,soshowandupdateit.
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();
m_pMainWnd->SetWindowText("软工二班尹异倾情打造");//输出窗口的名称
returnTRUE;
}
/////////////////////////////////////////////////////////////////////////////
//CAboutDlgdialogusedforAppAbout
classCAboutDlg:
publicCDialog
{
public:
CAboutDlg();
//DialogData
//{{AFX_DATA(CAboutDlg)
enum{IDD=IDD_ABOUTBOX};
//}}AFX_DATA
//ClassWizardgeneratedvirtualfunctionoverrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtualvoidDoDataExchange(CDataExchange*pDX);//DDX/DDVsupport
//}}AFX_VIRTUAL
//Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//Nomessagehandlers
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg:
:
CAboutDlg():
CDialog(CAboutDlg:
:
IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
voidCAboutDlg:
:
DoDataExchange(CDataExchange*pDX)
{
CDialog:
:
DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg,CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
//Nomessagehandlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
//Appcommandtorunthedialog
voidCMyApp:
:
OnAppAbout()
{
CAboutDlgaboutDlg;
aboutDlg.DoModal();
/////////////////////////////////////////////////////////////////////////////
//CMyAppmessagehandlers
}
[2]我的画图板加强版View.cpp
#include"stdafx.h"
#include"我的画图板加强版.h"
#include"我的画图板加强版Doc.h"
#include"我的画图板加强版View.h"
#include"LineWidth.h"
#include"MYFONT.h"
#include"LineStyle.h"
#include"BrushStyle.h"
#include"MainFrm.h"
#ifdef_DEBUG
#definenewDEBUG_NEW
#undefTHIS_FILE
staticcharTHIS_FILE[]=__FILE__;
#endif
externintlinewidth;
externintlinestyle;
/////////////////////////////////////////////////////////////////////////////
//CMyView
IMPLEMENT_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
//Standardprintingcommands
ON_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()
/////////////////////////////////////////////////////////////////////////////
//CMyViewconstruction/destruction
CMyView:
:
CMyView()
{lw=1;
r=0;
g=0;
b=0;
tag=false;
loop=1;
//TODO:
addconstructioncodehere
m_clean=false;
}
CMyView:
:
~CMyView()
{
}
BOOLCMyView:
:
PreCreateWindow(CREATESTRUCT&cs)
{
//TODO:
ModifytheWindowclassorstylesherebymodifying
//theCREATESTRUCTcs
returnCView:
:
PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
//CMyViewdrawing
voidCMyView:
:
OnDraw(CDC*pDC)
{
CMyDoc*pDoc=GetDocument();
ASSERT_VALID(pDoc);
if(!
m_clean)//m_clean是一个标志判断是否清空屏幕。
{
if(loop==1)//loop是一个标志判断为画笔还是画刷。
{CPenPen;
Pen.CreatePen(m_linestyle,lw,(m_color));
CPen*pOldPen=pDC->SelectObject(&Pen);
if(flag==1)//画线。
{pDC->MoveTo(start);
pDC->LineTo(end);
}
elseif(flag==2)//画矩形
{pDC->Rectangle(start.x,start.y,end.x,end.y);
}
elseif(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)填充色彩
{CBrushbrush;
brush.CreateSolidBrush(m_color);
CBrush*poldbrush=pDC->SelectObject(&brush);
pDC->FloodFill(start.x,start.y,m_color);
pDC->SelectObject(brush);
}
if(flag==8)//输出文本框
{
CFontmyFont;
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);}
elseif(loop==2)//实用画刷
{CBrushBr;
Br.CreateSolidBrush(m_color);
pDC->SelectObject(&Br);
if(flag==1)
{pDC->MoveTo(start);
pDC->LineTo(end);
}
elseif(flag==2)//填充矩形
{pDC->Rectangle(start.x,start.y,end.x,end.y);
}
elseif(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)//填充颜色
{CBrushbrush;
brush.CreateSolidBrush(m_color);
CBrush*poldbrush=pDC->SelectObject(&brush);
pDC->FloodFill(start.x,start.y,m_color);
pDC->SelectObject(poldbrush);
}
DeleteObject(Br);
}//TODO:
adddrawcodefornativedatahere
}
m_clean=false;
}
/////////////////////////////////////////////////////////////////////////////
//CMyViewprinting
BOOLCMyView:
:
OnPreparePrinting(CPrintInfo*pInfo)
{
//defaultpreparation
returnDoPreparePrinting(pInfo);
}
voidCMyView:
:
OnBeginPrinting(CDC*/*pDC*/,CPrintInfo*/*pInfo*/)
{
//TODO:
addextrainitializationbeforeprinting
}
voidCMyView:
:
OnEndPrinting(CDC*/*pDC*/,CPrintInfo*/*pInfo*/)
{
//TODO:
addcleanupafterprinting
}
/////////////////////////////////////////////////////////////////////////////
//CMyViewdiagnostics
#ifdef_DEBUG
voidCMyView:
:
AssertValid()const
{
CView:
:
AssertValid();
}
voidCMyView:
:
Dump(CDumpContext&dc)const
{
CView:
:
Dump(dc);
}
CMyDoc*CMyView:
:
GetDocument()//non-debugversionisinline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyDoc)));
return(CMyDoc*)m_pDocument;
}
#endif//_DEBUG
/////////////////////////////////////////////////////////////////////////////
//CMyViewmessagehandlers
voidCMyView:
:
OnLine()
{
flag=1;
//TODO:
Addyourcommandhandlercodehere
}
voidCMyView:
:
OnRectangle()
{
flag=2;
//TODO:
Addyourcommandhandlercodehere
}
voidCMy
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 简单 画图板 设计 报告
![提示](https://static.bdocx.com/images/bang_tan.gif)