C++画图板的论文.docx
- 文档编号:10983933
- 上传时间:2023-02-24
- 格式:DOCX
- 页数:62
- 大小:90.92KB
C++画图板的论文.docx
《C++画图板的论文.docx》由会员分享,可在线阅读,更多相关《C++画图板的论文.docx(62页珍藏版)》请在冰豆网上搜索。
C++画图板的论文
VC++课程设计
班级:
09计算机1班
姓名:
洪海洋
学号:
200901030121
日期:
2011年7月
VC++课程设计
设计目的:
1.掌握用VC++6.0开发环境开发软件的方法;
2.熟悉获得帮助的方法;
3.掌握SDI应用程序结构,熟悉基于对话框的应用程序编程方法;
4.掌握用资源编辑器进行图标,菜单,工具栏,对话框等资源的编辑;
5.掌握对话框,常用控件和ActiveX控件的使用方法;
6.熟悉文档/视图结构,掌握文档和视图的相互控制技巧;
设计选题:
开发一个小型绘图应用程序,具体要求如下:
1.具有标准Windows应用程序的界面和风格(视图要求滚动);
2.通过选择菜单或工具栏中相应功能完成基本几何图形的绘制(基本几何图形包括直线、圆、椭圆、矩形、多边形、扇形、弧等);
3.几何图形实现存盘和读取显示功能;
4.应用程序界面友好。
设计思路:
用于表征这些几何图形对象的数据是不同的,他们都有颜色、线形和线宽三个属性数据,但几何数据又各不相同。
直线、椭圆和矩形用两个坐标点数据表示,扇形和弧用四个坐标点数据表示。
另外对于封闭图形,还可以有填充与不填充的选择。
我们知道在VC++中,如果在基类定义把成员函数说明为虚函数,在派生类只对虚函数的函数体内容重新定义,保留函数名、返回值类型和参数不变,用一个指向基类的指针访问虚函数,就可以实现多态性。
所以,首先定义各个几何图形类。
在每个类中定义自己的几何数据,定义构造函数生成各自的图形对象,用来实现各自不同的数据序列化和屏幕重绘。
其次,在文档类中定义一个用来保存各二维图形对象指针的数组CDiffArray。
再次,修改OnDraw成员函数,以实现虚函数的多态性。
最后,实现不同图形对象的保存和重绘。
另外,用户界面包括菜单和工具两栏。
在菜单栏添加图形菜单和所属菜单项。
最后运行结果如下:
附录:
源程序清单
//CLine直线定义
classCLine:
publicCObject
{
DECLARE_SERIAL(CLine)
public:
boolbIsSelected;
intstartX;
intstartY;
intendX;
intendY;
LOGPENLinePen;
CLine();
virtual~CLine();
voidSerialize(CArchive&ar);
};
//CArc圆弧定义
classCArc:
publicCObject
{
DECLARE_SERIAL(CArc)
public:
boolbIsSelected;
intstartX;
intstartY;
intendX;
intendY;
LOGPENLinePen;
CArc();
virtual~CArc();
voidSerialize(CArchive&ar);
public:
CDifferdiffA;
CDifferdiffB;
};
//CRectangle矩形定义
classCRectangle:
publicCObject
{
DECLARE_SERIAL(CRectangle)
public:
boolbIsSelected;
intstartX;
intstartY;
intendX;
intendY;
LOGPENLinePen;
LOGBRUSHMyBrush;
voidSerialize(CArchive&ar);
CRectangle();
virtual~CRectangle();
};
//CPoloygon多边形定义
classCPoloygon:
publicCObject
{
DECLARE_SERIAL(CPoloygon)
public:
boolbIsSelected;
intstartX;
intstartY;
intendX;
intendY;
CDiffArraydiffArray;
LOGPENLinePen;
CPoloygon();
virtual~CPoloygon();
voidSerialize(CArchive&ar);
};
//CPie扇形定义
classCPie:
publicCObject
{
DECLARE_SERIAL(CPie)
public:
boolbIsSelected;
intstartX;
intstartY;
intendX;
intendY;
LOGPENLinePen;
LOGBRUSHMyBrush;
CPie();
virtual~CPie();
voidSerialize(CArchive&ar);
public:
CDifferdiffA;
CDifferdiffB;
};
//CEllipse椭圆形定义
classCEllipse:
publicCObject
{
DECLARE_SERIAL(CEllipse)
public:
boolbIsSelected;
intstartX;
intstartY;
intendX;
intendY;
LOGPENLinePen;
LOGBRUSHMyBrush;
CEllipse();
virtual~CEllipse();
voidSerialize(CArchive&ar);
};
//Cline实现代码
classCLineProperties:
publicCDialog
{
public:
COLORREFm_LineColor;
CLineProperties(CWnd*pParent=NULL);//standardconstructor
enum{IDD=IDD_DIALOG_LINE};
CButtonm_BtnColor;
CStringm_LineWidth;
CStringm_LineStyle;
protected:
virtualvoidDoDataExchange(CDataExchange*pDX);//DDX/DDVsupport
protected:
virtualBOOLOnInitDialog();
afx_msgvoidOnButtonColor();
DECLARE_MESSAGE_MAP()
};
CLineProperties:
:
CLineProperties(CWnd*pParent/*=NULL*/)
:
CDialog(CLineProperties:
:
IDD,pParent)
{
//{{AFX_DATA_INIT(CLineProperties)
m_LineWidth=_T("");
m_LineStyle=_T("");
//}}AFX_DATA_INIT
}
voidCLineProperties:
:
DoDataExchange(CDataExchange*pDX)
{
CDialog:
:
DoDataExchange(pDX);
//{{AFX_DATA_MAP(CLineProperties)
DDX_Control(pDX,IDC_BUTTON_COLOR,m_BtnColor);
DDX_CBString(pDX,IDC_LINEWIDTH,m_LineWidth);
DDX_CBString(pDX,IDC_LINESTYLE,m_LineStyle);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CLineProperties,CDialog)
//{{AFX_MSG_MAP(CLineProperties)
ON_BN_CLICKED(IDC_BUTTON_COLOR,OnButtonColor)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
//CLinePropertiesmessagehandlers
BOOLCLineProperties:
:
OnInitDialog()
{
CDialog:
:
OnInitDialog();
//TODO:
Addextrainitializationhere
CStringstr_RGB;
str_RGB.Format("%d:
%d:
%d",GetRValue(m_LineColor),
GetGValue(m_LineColor),GetBValue(m_LineColor));
this->m_BtnColor.SetWindowText(str_RGB);
returnTRUE;//returnTRUEunlessyousetthefocustoacontrol
//EXCEPTION:
OCXPropertyPagesshouldreturnFALSE
}
voidCLineProperties:
:
OnButtonColor()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
CColorDialogdlg(RGB(255,0,0));
if(dlg.DoModal()==IDOK)
{
m_LineColor=dlg.GetColor();
CStringstr_RGB;
str_RGB.Format("%d:
%d:
%d",GetRValue(m_LineColor),
GetGValue(m_LineColor),GetBValue(m_LineColor));
this->m_BtnColor.SetWindowText(str_RGB);
}
}
IMPLEMENT_SERIAL(CLine,CObject,1)
voidCLine:
:
Serialize(CArchive&ar)
{
CObject:
:
Serialize(ar);
if(ar.IsLoading())
{
ar>>startX>>startY>>endX>>endY>>LinePen.lopnWidth.x
>>LinePen.lopnColor>>LinePen.lopnStyle;
}
else
{
ar< < } } //CArc实现代码 IMPLEMENT_SERIAL(CArc,CObject,1) CArc: : CArc() { bIsSelected=false; LinePen.lopnWidth.x=1; LinePen.lopnColor=RGB(0,0,0); LinePen.lopnStyle=PS_SOLID; } CArc: : ~CArc() { } voidCArc: : Serialize(CArchive&ar) { CObject: : Serialize(ar); if(ar.IsLoading()) { ar>>startX>>startY>>endX>>endY>> LinePen.lopnWidth.x>>LinePen.lopnColor>>LinePen.lopnStyle; diffA.Serialize(ar); diffB.Serialize(ar); } else { ar< LinePen.lopnWidth.x< diffA.Serialize(ar); diffB.Serialize(ar); } } //CRectangle实现代码 IMPLEMENT_SERIAL(CRectangle,CObject,1) CRectangle: : CRectangle() { LinePen.lopnWidth.x=1; LinePen.lopnColor=RGB(255,255,255); LinePen.lopnStyle=PS_SOLID; MyBrush.lbColor=RGB(255,255,255); MyBrush.lbHatch=HS_CROSS; MyBrush.lbStyle=BS_NULL; } CRectangle: : ~CRectangle() { } voidCRectangle: : Serialize(CArchive&ar) { CObject: : Serialize(ar); if(ar.IsLoading()) { ar>>startX>>startY>>endX>>endY>> LinePen.lopnWidth.x>>LinePen.lopnColor>>LinePen.lopnStyle>> MyBrush.lbColor>>MyBrush.lbHatch>>MyBrush.lbStyle; } else { ar< LinePen.lopnColor< MyBrush.lbColor< } } //CPoloygon实现代码 IMPLEMENT_SERIAL(CPoloygon,CObject,1) CPoloygon: : CPoloygon() { bIsSelected=false; LinePen.lopnWidth.x=1; LinePen.lopnColor=RGB(0,0,0); LinePen.lopnStyle=PS_SOLID; } CPoloygon: : ~CPoloygon() { } voidCPoloygon: : Serialize(CArchive&ar) { CObject: : Serialize(ar); if(ar.IsLoading()) { ar>>startX>>startY>>endX>>endY>> LinePen.lopnWidth.x>>LinePen.lopnColor>>LinePen.lopnStyle; diffArray.Serialize(ar); } else { ar< LinePen.lopnWidth.x< diffArray.Serialize(ar); } } //CEllipse实现代码 classCEllipseProperties: publicCDialog { public: COLORREFm_LineColor; COLORREFm_BrushColor; CEllipseProperties(CWnd*pParent=NULL);//standardconstructor enum{IDD=IDD_DIALOG_ELLIPSE}; CButtonm_BtnBrushColor; CButtonm_BtnColor; CStringm_LineWidth; CStringm_LineStyle; CStringm_HatchStyle; CStringm_BrushStyle; protected: virtualvoidDoDataExchange(CDataExchange*pDX);//DDX/DDVsupport protected: afx_msgvoidOnButtonColor(); afx_msgvoidOnButtonBrushcolor(); virtualBOOLOnInitDialog(); DECLARE_MESSAGE_MAP() }; CEllipseProperties: : CEllipseProperties(CWnd*pParent/*=NULL*/) : CDialog(CEllipseProperties: : IDD,pParent) { //{{AFX_DATA_INIT(CEllipseProperties) m_LineWidth=_T(""); m_LineStyle=_T(""); m_HatchStyle=_T(""); m_BrushStyle=_T(""); //}}AFX_DATA_INIT } voidCEllipseProperties: : DoDataExchange(CDataExchange*pDX) { CDialog: : DoDataExchange(pDX); //{{AFX_DATA_MAP(CEllipseProperties) DDX_Control(pDX,IDC_BUTTON_BRUSHCOLOR,m_BtnBrushColor); DDX_Control(pDX,IDC_BUTTON_COLOR,m_BtnColor); DDX_CBString(pDX,IDC_LINEWIDTH,m_LineWidth); DDX_CBString(pDX,IDC_LINESTYLE,m_LineStyle); DDX_CBString(pDX,IDC_HATCHSTYLE,m_HatchStyle); DDX_CBString(pDX,IDC_BRUSHSTYLE,m_BrushStyle); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CEllipseProperties,CDialog) //{{AFX_MSG_MAP(CEllipseProperties) ON_BN_CLICKED(IDC_BUTTON_COLOR,OnButtonColor) ON_BN_CLICKED(IDC_BUTTON_BRUSHCOLOR,OnButtonBrushcolor) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// //CEllipsePropertiesmessagehandlers voidCEllipseProperties: : OnButtonColor() { //TODO: Addyourcontrolnotificationhandlercodehere CColorDialogdlg(m_LineColor); if(dlg.DoModal()==IDOK) { m_LineColor=dlg.GetColor(); CStringstr_RGB; str_RGB.Format("%d: %d: %d",GetRValue(m_LineColor), GetGValue(m_LineColor),GetBValue(m_LineColor)); this->m_BtnColor.SetWindowText(str_RGB); } } voidCEllipseProperties: : OnButtonBrushcolor() { //TODO: Addyourcontrolnotificationhandlercodehere CColorDialogdlg(m_BrushColor); if(dlg.DoModal()==IDOK) { m_BrushColor=dlg.GetColor(); CStringstr_RGB; str_RGB.Format("%d: %d: %d",GetRValue(m_BrushColor), GetGValue(m_BrushColor),GetBValue(m_BrushColor)); this->m_BtnBrushColor.SetWindowText(str_RGB); } } BOOLCEllipseProperties: : OnInitDialog() { CDialog: : OnInitDialog(); //TODO: Addextrainitializationhere CStringstr_RGB; str_RGB.Format("%d: %d: %d",GetRValue(m_LineColor), GetGValue(m_LineColor),GetBValue(m_LineColor)); this->m_BtnColor.SetWindowText(str_RGB); str_RGB.Format("%d: %d: %d",GetRValue(m_BrushColor), GetGValue(m_BrushColor),GetBValue(m_BrushColor)); this->m_BtnBrushColor.SetWindowText(str_RGB); returnTRUE;//returnTRUEunlessyousetthefocustoacontrol //EXCEPTION: OCXPropertyPagesshouldreturnFALSE } IMPLEMENT_SERIAL(CEllipse,CObject,1) CEllipse: : CEllipse() { LinePen.lopnWidth.x=1; LinePen.lopnColor=RGB(0,0,0); LinePen.lopnStyle=PS_SOLID; MyB
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- C+ 画图板 论文
