資源描述:
《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){m
8、_crBackColor=color;}COLORREFCLine::GetBkColor(){returnm_crBackColor;}voidCLine::SetWidth(intiWidth){m_logPen.lopnWidth.x=iWidth;m_l