欢迎来到天天文库
浏览记录
ID:39464336
大小:52.28 KB
页数:10页
时间:2019-07-03
《Ado实现C++对象的存取》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、Ado实现C++对象的存取作者:江上飞鸟下载源代码 其实我最讨厌写东西了,最近忙死了,呵呵,前一段时间在做一个图形程序时,需要把C++对象保存到数据库里,刚开始真让我头疼啊,琢磨了一个下午,终于给做出来了,废话不说了,还是把自己的一些体会与各位同任一起分享!!!!一、新建一个继承于CObject的子类CLine;头文件:Line.hclassCLine:publicCObject?{private:LOGPENm_logPen;//画笔COLORREFm_crBackColor;CArraym_
2、PointArray;//标记类对应框public:intGetSize();CPointGetPoint(intpos);voidDrawLine(CDC*pDC,CPointpt1,CPointpt2,CRectrc);voidDrawBackGround(CDC*pDC,CRectrect);voidDrawPoint(CDC*pDC,CRectrect);voidSetWidth(intiWidth);COLORREFGetColor();voidSetColor(COLORREFcolor);COLORREFGetBk
3、Color();voidSetBkColor(COLORREFcolor);voidAddPoint(CPointpoint);voidClear();CLine();virtual~CLine();virtualvoidSerialize(CArchive&ar);CLine&operator=(CLine&src);DECLARE_SERIAL(CLine)??};实现文件:Line.cpp////////////////////////////////////////////////////////////////////
4、////Line.cpp:implementationoftheCLineclass.////////////////////////////////////////////////////////////////////////#include"stdafx.h"#include"TestAdo.h"#include"Line.h"#ifdef_DEBUG#undefTHIS_FILEstaticcharTHIS_FILE[]=__FILE__;#definenewDEBUG_NEW#endifIMPLEMENT_SERIAL
5、(CLine,CObject,1)CLine::CLine(){Clear();}CLine::~CLine(){}//重写=CLine&CLine::operator=(CLine&src){if(this!=&src){m_logPen=src.m_logPen;m_crBackColor=src.m_crBackColor;}return*this;?}//串行化操作voidCLine::Serialize(CArchive&ar){if(ar.IsStoring()){ar<6、r.Write(&m_logPen,sizeof(LOGPEN));}else{DWORDdw;ar>>dw;m_crBackColor=COLORREF(dw);ar.Read(&m_logPen,sizeof(LOGPEN));}m_PointArray.Serialize(ar);}voidCLine::Clear(){m_crBackColor=RGB(255,255,255);m_logPen.lopnStyle=PS_SOLID;m_logPen.lopnWidth.x=1;m_logPen.lopnWidth.y=7、1;m_logPen.lopnColor=RGB(0,0,0);m_PointArray.RemoveAll();}voidCLine::AddPoint(CPointpoint){m_PointArray.Add(point);}voidCLine::SetColor(COLORREFcolor){m_logPen.lopnColor=color;}COLORREFCLine::GetColor(){returnm_logPen.lopnColor;}voidCLine::SetBkColor(COLORREFcolor){m8、_crBackColor=color;}COLORREFCLine::GetBkColor(){returnm_crBackColor;}voidCLine::SetWidth(intiWidth){m_logPen.lopnWidth.x=iWidth;m_l
6、r.Write(&m_logPen,sizeof(LOGPEN));}else{DWORDdw;ar>>dw;m_crBackColor=COLORREF(dw);ar.Read(&m_logPen,sizeof(LOGPEN));}m_PointArray.Serialize(ar);}voidCLine::Clear(){m_crBackColor=RGB(255,255,255);m_logPen.lopnStyle=PS_SOLID;m_logPen.lopnWidth.x=1;m_logPen.lopnWidth.y=
7、1;m_logPen.lopnColor=RGB(0,0,0);m_PointArray.RemoveAll();}voidCLine::AddPoint(CPointpoint){m_PointArray.Add(point);}voidCLine::SetColor(COLORREFcolor){m_logPen.lopnColor=color;}COLORREFCLine::GetColor(){returnm_logPen.lopnColor;}voidCLine::SetBkColor(COLORREFcolor){m
8、_crBackColor=color;}COLORREFCLine::GetBkColor(){returnm_crBackColor;}voidCLine::SetWidth(intiWidth){m_logPen.lopnWidth.x=iWidth;m_l
此文档下载收益归作者所有