MFC绘图版 软件说明书Word下载.docx

上传人:b****4 文档编号:6730754 上传时间:2023-05-07 格式:DOCX 页数:41 大小:52KB
下载 相关 举报
MFC绘图版 软件说明书Word下载.docx_第1页
第1页 / 共41页
MFC绘图版 软件说明书Word下载.docx_第2页
第2页 / 共41页
MFC绘图版 软件说明书Word下载.docx_第3页
第3页 / 共41页
MFC绘图版 软件说明书Word下载.docx_第4页
第4页 / 共41页
MFC绘图版 软件说明书Word下载.docx_第5页
第5页 / 共41页
MFC绘图版 软件说明书Word下载.docx_第6页
第6页 / 共41页
MFC绘图版 软件说明书Word下载.docx_第7页
第7页 / 共41页
MFC绘图版 软件说明书Word下载.docx_第8页
第8页 / 共41页
MFC绘图版 软件说明书Word下载.docx_第9页
第9页 / 共41页
MFC绘图版 软件说明书Word下载.docx_第10页
第10页 / 共41页
MFC绘图版 软件说明书Word下载.docx_第11页
第11页 / 共41页
MFC绘图版 软件说明书Word下载.docx_第12页
第12页 / 共41页
MFC绘图版 软件说明书Word下载.docx_第13页
第13页 / 共41页
MFC绘图版 软件说明书Word下载.docx_第14页
第14页 / 共41页
MFC绘图版 软件说明书Word下载.docx_第15页
第15页 / 共41页
MFC绘图版 软件说明书Word下载.docx_第16页
第16页 / 共41页
MFC绘图版 软件说明书Word下载.docx_第17页
第17页 / 共41页
MFC绘图版 软件说明书Word下载.docx_第18页
第18页 / 共41页
MFC绘图版 软件说明书Word下载.docx_第19页
第19页 / 共41页
MFC绘图版 软件说明书Word下载.docx_第20页
第20页 / 共41页
亲,该文档总共41页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

MFC绘图版 软件说明书Word下载.docx

《MFC绘图版 软件说明书Word下载.docx》由会员分享,可在线阅读,更多相关《MFC绘图版 软件说明书Word下载.docx(41页珍藏版)》请在冰点文库上搜索。

MFC绘图版 软件说明书Word下载.docx

直线,带箭头的线,任意线,圆形,椭圆,矩形。

2)可以对画笔进行设置:

画笔的颜色,画笔的线宽,画笔的形状。

3)可以保存所有的图形到存中,所有图形绘制后,拉动窗口发生重绘不改变。

4)可以将所有绘制的图形保存到文件中,并且可以读取。

5)可以“新建”空白绘图文档。

6)可以查看最近打开的文档。

7)可以打印用户绘制好后的图形,打印预览你绘制的图形。

8)可以完成一部分的“撤消”功能,(注:

任意曲线的图形绘制撤消不能实现)

9)可以完成图形“清空”功能。

有以下几个次要功能

1)有个软件启动画面。

2)有个绘图工具栏。

3)在状态栏可以显示鼠标的坐标和当前的时间。

4)可以打开txt文本文件,并且修改字体。

5)可以打开bmp图像文件,并且显示图像。

6)可以打开wav音频文件,并且播放音乐。

2.总体设计

本程序用的MFC中的单文档文档/视图类结构。

在视图类中完成图形的绘制,显示,重绘,清空,撤消,设置画笔,设置字体,打开txt,wav,bmp文件。

在文档类保存了,绘制图形的各种数据,所有图形的点的坐标,画笔的信息。

3.详细设计

设计了保存图形的类

classCGraph:

publicCObject//派生于CObject

{//将CGraph串行话需要5个步骤

//1.要派生于CObject类

//2.重新写voidSerialize(CArchive&

ar)

//3.正在头文件定义宏定义DECLARE_SERIAL(CGraphPoint)

//4.无参数的构造函数CGraph();

//5.在实现文件cpp中使用宏定义DECLARE_SERIAL(CGraph,CObject,1/*类的版本号*/)

DECLARE_SERIAL(CGraph)//文档串行化的宏定义DECLARE_SERIAL(CGraph)

public:

voidSerialize(CArchive&

ar);

//重新写Serialize函数

voidDraw(CDC*pDC);

//绘图的方法

UINTm_DrawIndex;

//绘图的类型

CPointm_FirstPoint;

//起始坐标

CPointm_SecondPoint;

//结束坐标

COLORREFm_color;

//颜色

UINTm_nLineWidth;

//线宽í

intm_nLineStyle;

//线形

CGraph();

CGraph(UINTDrawIndex,CPointFirstPoint,CPointSecondPoint,COLORREFcolor,UINTLineWidth,intLineStyle);

//4个参数构造函数

virtual~CGraph();

};

实现文件

IMPLEMENT_SERIAL(CGraph,CObject,1)

//文档串行化的宏定义DECLARE_SERIAL(CGraph)

CGraph:

:

CGraph()

{

}

CGraph(UINTDrawIndex,CPointFirstPoint,CPointSecondPoint,COLORREFcolor,UINTLineWidth,intLineStyle)

{//5¸

ö

²

Î

Ê

ý

µ

Ä

¹

Ô

ì

º

¯

this->

m_DrawIndex=DrawIndex;

m_FirstPoint=FirstPoint;

m_SecondPoint=SecondPoint;

m_color=color;

m_nLineStyle=LineStyle;

m_nLineWidth=LineWidth;

~CGraph()

voidCGraph:

Draw(CDC*pDC)

{//CGraphµ

»

æ

½

·

¨

¸

ù

¾

Ý

m_DrawIndexµ

Í

¬

µ

÷

Ó

Ã

CPenhpen(m_nLineStyle,m_nLineWidth,m_color);

CBrush*pBrush=CBrush:

FromHandle((HBRUSH)GetStockObject(NULL_BRUSH));

CBrush*pOldBrush=pDC->

SelectObject(pBrush);

switch(m_DrawIndex)

{

case1:

pDC->

SelectObject(&

hpen);

MoveTo(m_FirstPoint);

LineTo(m_SecondPoint);

break;

case2:

case3:

{

floatflRlt;

flRlt=(float)((m_FirstPoint.x-m_SecondPoint.x)*(m_FirstPoint.x-m_SecondPoint.x)+(m_FirstPoint.y-m_SecondPoint.y)*(m_FirstPoint.y-m_SecondPoint.y));

flRlt=sqrt(flRlt);

if(flRlt==0)

return;

floatflLength=15;

floatflAngle=100;

//É

è

Ö

Ð

Ï

ò

¼

Ç

È

floattmpX=(float)(m_SecondPoint.x)+((float)(m_FirstPoint.x)-(float)(m_SecondPoint.x))*flLength/flRlt;

floattmpY=(float)(m_SecondPoint.y)+((float)(m_FirstPoint.y)-(float)(m_SecondPoint.y))*flLength/flRlt;

floatfl1X=(tmpX-(float)(m_SecondPoint.x))*cos(-flAngle/2)-(tmpY-(float)(m_SecondPoint.y))*sin(-flAngle/2)+(float)(m_SecondPoint.x);

floatfl1Y=(tmpY-(float)(m_SecondPoint.y))*cos(-flAngle/2)+(tmpX-(float)(m_SecondPoint.x))*sin(-flAngle/2)+(float)(m_SecondPoint.y);

floatfl2X=(tmpX-(float)(m_SecondPoint.x))*cos(flAngle/2)-(tmpY-(float)(m_SecondPoint.y))*sin(flAngle/2)+(float)(m_SecondPoint.x);

floatfl2Y=(tmpY-(float)(m_SecondPoint.y))*cos(flAngle/2)+(tmpX-(float)(m_SecondPoint.x))*sin(flAngle/2)+(float)(m_SecondPoint.y);

MoveTo(m_SecondPoint.x,m_SecondPoint.y);

LineTo(fl1X,fl1Y);

LineTo(fl2X,fl2Y);

MoveTo(fl1X,fl1Y);

}

case4:

Ellipse(CRect(m_FirstPoint,m_SecondPoint));

SelectObject(pOldBrush);

case5:

case6:

Rectangle(CRect(m_FirstPoint,m_SecondPoint));

}

Serialize(CArchive&

ar)

{//Ó

CArchive½

ø

þ

Ù

×

//>

>

Ë

³

<

Ò

ª

à

if(ar.IsStoring())

ar<

m_DrawIndex<

m_FirstPoint<

m_SecondPoint<

m_color<

m_nLineWidth<

m_nLineStyle;

else

ar>

m_DrawIndex>

m_FirstPoint>

m_SecondPoint>

m_color>

m_nLineWidth>

;

任意曲线类

classCStroke:

publicCObject//È

â

ú

ß

À

CStroke(UINTnPenWidth,COLORREFcolor);

protected:

CStroke();

DECLARE_SERIAL(CStroke)

//Attributes

UINTm_nPenWidth;

//onepenwidthappliestoentirestroke

//颜色

CArray<

CPoint,CPoint>

m_pointArray;

//seriesofconnectedpoints

//Operations

BOOLDrawStroke(CDC*pDC);

virtualvoidSerialize(CArchive&

ar);

实现文件CStroke.cpp

IMPLEMENT_SERIAL(CStroke,CObject,2)

CStroke:

CStroke()

//Thisemptyconstructorshouldbeusedbyserializationonly

CStroke(UINTnPenWidth,COLORREFcolor)

m_nPenWidth=nPenWidth;

m_color=color;

voidCStroke:

Serialize(CArchive&

ar)

if(ar.IsStoring())

ar<

(WORD)m_nPenWidth<

m_color;

m_pointArray.Serialize(ar);

WORDw;

ar>

w>

m_nPenWidth=w;

BOOLCStroke:

DrawStroke(CDC*pDC)

CPenpenStroke;

if(!

penStroke.CreatePen(PS_SOLID,m_nPenWidth,m_color))

returnFALSE;

CPen*pOldPen=pDC->

penStroke);

pDC->

MoveTo(m_pointArray[0]);

for(inti=1;

i<

m_pointArray.GetSize();

i++)

LineTo(m_pointArray[i]);

SelectObject(pOldPen);

returnTRUE;

线形状和线宽设置对话框类

classCSettingDlg:

publicCDialog

CSettingDlg(CWnd*pParent=NULL);

//{{AFX_DATA(CSettingDlg)

enum{IDD=IDD_DIALOG1};

//线宽

//线形状

//线的颜色

//}}AFX_DATA

//Overrides

//ClassWizardgeneratedvirtualfunctionoverrides

//{{AFX_VIRTUAL(CSettingDlg)

protected:

virtualvoidDoDataExchange(CDataExchange*pDX);

//DDX/DDVsupport

//}}AFX_VIRTUAL

//Generatedmessagemapfunctions

//{{AFX_MSG(CSettingDlg)

afx_msgvoidOnPaint();

//}}AFX_MSG

DECLARE_MESSAGE_MAP()

实现文件CSettingDlg.cpp

CSettingDlg:

CSettingDlg(CWnd*pParent/*=NULL*/)

:

CDialog(CSettingDlg:

IDD,pParent)

//{{AFX_DATA_INIT(CSettingDlg)

m_nLineWidth=0;

m_nLineStyle=-1;

//}}AFX_DATA_INIT

voidCSettingDlg:

DoDataExchange(CDataExchange*pDX)

CDialog:

DoDataExchange(pDX);

//{{AFX_DATA_MAP(CSettingDlg)

DDX_Text(pDX,IDC_EDIT2,m_nLineWidth);

DDX_Radio(pDX,IDC_RADIO1,m_nLineStyle);

//}}AFX_DATA_MAP

BEGIN_MESSAGE_MAP(CSettingDlg,CDialog)

//{{AFX_MSG_MAP(CSettingDlg)

ON_WM_PAINT()

//}}AFX_MSG_MAP

END_MESSAGE_MAP()

//CSettingDlgmessagehandlers

OnPaint()

{//这里添加了代码用于对话框的示例显示

CPaintDCdc(this);

//devicecontextforpainting

//TODO:

Addyourmessagehandlercodehere

UpdateData();

CPenpen(m_nLineStyle,m_nLineWidth,m_color);

//定义画笔

dc.SelectObject(&

pen);

CRectrect;

//定义矩形区域

GetDlgItem(IDC_STATIC1)->

GetWindowRect(&

rect);

//得到示例静态空间的矩形区域

ScreenToClient(&

///坐标转换

dc.MoveTo(rect.left+20,rect.top+rect.Height()/2);

dc.LineTo(rect.right-20,rect.top+rect.Height()/2);

//DonotcallCDialog:

OnPaint()forpaintingmessages

在CMainFrame中添加的代码

添加成员变量CToolBarm_newToolBar一个新的绘图工具栏

在CMainFrame中的OnCreat()函数中添加的代码:

CSplashWnd:

ShowSplashScreen(this);

//启动画面

Sleep(1000);

//程序暂停

//------------------新建画图工具栏-----------------------------------//

if(!

m_newToolBar.CreateEx(this,TBSTYLE_FLAT,WS_CHILD|WS_VISIBLE|CBRS_TOP|

CBRS_GRIPPER|CBRS_TOOLTIPS|CBRS_FLYBY|CBRS_SIZE_DYNAMIC)||

!

m_newToolBar.LoadToolBar(IDR_DRAW_TOOLBAR))

TRACE0("

Failedtocreatetoolbar\n"

);

return-1;

//failtocreate

m_newToolBar.EnableDocking(CBRS_ALIGN_ANY);

EnableDocking(CBRS_ALIGN_ANY);

DockControlBar(&

m_newToolBar);

在CMFCDoc中添加的代码

CMFCDoc.h中

virtual~CMFCDoc();

CPenm_penCur;

//pencreatedaccordingto

CTypedPtrList<

CObList,CStroke*>

m_strokeList;

//currentuser-selectedpenwidth

//颜色«

CPen*GetCurrentPen();

CStroke*NewStroke();

voidInitDocument();

//初始化任意曲线的画笔

voidDeleteContents();

//删除任意曲线

BOOLOnOpenDocument(LPCTSTRlpszPathName);

CMFCDoc.cpp中

CStroke*CMFCDoc:

NewStroke()

{//Ð

Â

newStrokeº

POSITIONpos=GetFirstViewPosition();

CMFCView*pView=(CMFCView*)GetNextView(pos);

//获取视类的指针

//获取视类的画笔宽度和颜色

m_nPenWidth=pView->

m_nLineWidth;

m_color=pView->

m_color;

CStroke*pStrokeItem=newCStroke(m_nPenWidth,m_color);

m_strokeList.AddTail(pStrokeItem);

SetModifiedFlag();

//Markthedocumentashavingbeenmodified,for

//purposesofconfirmingFileClose.

returnpStrokeItem;

BOOLCMFCDoc:

OnNewDocument()

{/新建空白文档

CDocument:

OnNewDocument())

addreinitializationcodehere

//(SDIdocumentswillreusethisdocument)

/新建空白文档就是把当前的数据全部删除掉

intmax=pView->

m_graph.GetSize();

for(inti=0;

i<

max;

i++)

pView->

m_graph.RemoveAt(max-i-1);

////////////////////////

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 经管营销 > 经济市场

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2