WEB开发网
开发学院软件开发VC Ado实现C++对象的存取 阅读

Ado实现C++对象的存取

 2010-02-19 20:33:35 来源:WEB开发网   
核心提示:实现文件:Line.cpp Line.cpp: implementation of the CLine class.#include "stdafx.h"#include "TestAdo.h"#include "Line.h"#ifdef _DEBUG#un

实现文件:Line.cpp

//////////////////////////////////////////////////////////////////////
// Line.cpp: implementation of the CLine class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "TestAdo.h"
#include "Line.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
IMPLEMENT_SERIAL(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;?
}
//串行化操作
void CLine::Serialize(CArchive &ar)
{
   if (ar.IsStoring())
   {
     ar << DWORD(m_crBackColor);
     ar.Write(&m_logPen, sizeof(LOGPEN));
   }
   else
   {
     DWORD dw;
     ar >> dw; m_crBackColor = COLORREF(dw);
     ar.Read(&m_logPen, sizeof(LOGPEN));
   }
   m_PointArray.Serialize(ar);
}
void CLine::Clear()
{
   m_crBackColor = RGB(255,255,255);
   m_logPen.lopnStyle = PS_SOLID;
   m_logPen.lopnWidth.x = 1;
   m_logPen.lopnWidth.y = 1;
   m_logPen.lopnColor = RGB(0, 0, 0);
   m_PointArray.RemoveAll();
}
void CLine::AddPoint(CPoint point)
{
   m_PointArray.Add(point);
}
void CLine::SetColor(COLORREF color)
{
   m_logPen.lopnColor = color;
}
COLORREF CLine::GetColor()
{
   return m_logPen.lopnColor;
}
void CLine::SetBkColor(COLORREF color)
{
   m_crBackColor = color;
}
COLORREF CLine::GetBkColor()
{
   return m_crBackColor;
}
void CLine::SetWidth(int iWidth)
{
   m_logPen.lopnWidth.x = iWidth;
   m_logPen.lopnWidth.y = iWidth;

}
//绘线条
void CLine::DrawPoint(CDC *pDC, CRect rect)
{
   int len = m_PointArray.GetSize();
   if (len <=0) return;
   CPen pen;
   pen.CreatePenIndirect(&m_logPen);
   CPen *pOldPen = pDC->SelectObject(&pen);
   CPoint pt = m_PointArray.GetAt(0);
   pDC->MoveTo(pt);
   for (int i=1; i< len; i++)
   {
     pt = m_PointArray.GetAt(i);
     pDC->LineTo(pt);
   }
   pDC->SelectObject(pOldPen);
   pOldPen = NULL;
   pen.DeleteObject();
}
void CLine::DrawBackGround(CDC *pDC, CRect rect)
{
   CBrush brushCtl;
   brushCtl.CreateSolidBrush(GetBkColor());
   pDC->Rectangle(rect);
   pDC->FillRect(rect,&brushCtl) ;
   brushCtl.DeleteObject();
}
void CLine::DrawLine(CDC *pDC,CPoint pt1, CPoint pt2, CRect rc)
{
   CPen pen;
   pen.CreatePenIndirect(&m_logPen);
   CPen *pOldPen = pDC->SelectObject(&pen);
   pDC->MoveTo(pt1);
   pDC->LineTo(pt2);
   pDC->SelectObject(pOldPen);
   pOldPen = NULL;
   pen.DeleteObject();
}
CPoint CLine::GetPoint(int pos)
{
   if (pos>=0 && pos<m_PointArray.GetSize())?
   {
     return m_PointArray.GetAt(pos);
   }
   return CPoint(0,0);
}
int CLine::GetSize()
{
   return m_PointArray.GetSize();
}

上一页  1 2 3 4  下一页

Tags:Ado 实现 对象

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接