我的第一个软件

经过了半个月的实习,学到了很多东西,尤其是知道什么是真正的团队精神。

企业需要什么样的团队。通过这半个月,我的团队也编写了我们的第一个软件:

VISOCHART绘图软件。尽管功能简单,不过还是蛮实用的。总的来说这就是我的

一点点进步吧。

程序的部分代码:

#pragma once
#include "afx.h"

// base: element
class CDrawingElement : public CObject
{
 DECLARE_SERIAL(CDrawingElement)
public:

 virtual ~CDrawingElement(void) {};

 // Virtual draw operation
 virtual void Draw(CDC* pDC, const CDrawingElement* pElement = 0) const {};
 virtual void Move(const CSize& Size) {};     // Move an element
 CRect GetBoundRect(void) const;              // Get the bounding rectangle for an element

 virtual void Serialize(CArchive& ar);      // Serialize function for CDrawingElement

protected:
 COLORREF m_crColor;                        // Color of an element
 CRect    m_EnclosingRect;                  // Rectangle enclosing an element
 int      m_nPenWidth;                      // Pen width
 int      m_nPenStyle;                      // Pen style
protected:
 CDrawingElement(void) {};
};

//=========================曲线===============================

// 基类: curve element
class CDrawingCurve : public CDrawingElement
{
 DECLARE_SERIAL(CDrawingCurve)

public:
 // 曲线的显示函数
 virtual void Draw(CDC* pDC, const CDrawingElement* pElement = 0) const;
 virtual void Move(const CSize& aSize);       // Function to move an element

 // 创建 a CDrawingCurve 对象
 CDrawingCurve(const CPoint& FirstPoint, const CPoint& SecondPoint,
  const COLORREF& Color, const int penStyle,const int &PenWidth);

 virtual void Serialize(CArchive& ar);      // Serialize function for CDrawingCurve

 void AddSegment(const CPoint& pt);     //Add a segment to the CDrawingCurve

protected:
 // CDrawingCurve data members to go here
 CList<CPoint, const CPoint&> m_PointList;

 CDrawingCurve(){};           // Default constructor - should not be used
};
//=========================直线===============================
class CDrawingLine : public CDrawingElement
{
 DECLARE_SERIAL(CDrawingLine)

public:
 // Function to display a line
 virtual void Draw(CDC* pDC, const CDrawingElement* pElement = 0) const;
 virtual void Move(const CSize& aSize);       // Function to move an element
 virtual void Serialize(CArchive& ar);      // Serialize function for CDrawingLine

 // Constructor for a line object
 CDrawingLine(const CPoint& ptStart, const CPoint& ptEnd,
  const COLORREF& crColor, const int nPenStyle,const int &PenWidth);

protected:
 CPoint m_StartPoint;          // Start point of line
 CPoint m_EndPoint;            // End point of line

 CDrawingLine(){}             // Default constructor - should not be used
};


//========================椭圆=====================
class CDrawingEllipse : public CDrawingElement
{
 DECLARE_SERIAL(CDrawingEllipse)

public:
 // Function to display a circle or an ellipse
 virtual void Draw(CDC* pDC, const CDrawingElement* pElement = 0) const;
 virtual void Move(const CSize& aSize);     // Function to move an element
 virtual void Serialize(CArchive& ar);      // Serialize function for CDrawingEllipse

 // Constructor for a circle or an ellipse
 CDrawingEllipse(const CPoint& ptStart, const CPoint& ptEnd,
  const COLORREF& crColor, const int nPenStyle,const int &PenWidth,
  const WORD wElement);

protected:
 WORD m_wElement;
 CDrawingEllipse() {};           // Default constructor - should not be used
};

//=========================矩形===============================

class CDrawingRectangle : public CDrawingElement
{
 DECLARE_SERIAL(CDrawingRectangle)

public:
 // Function to display a rectangle
 virtual void Draw(CDC* pDC, const CDrawingElement* pElement = 0) const;
 virtual void Move(const CSize& aSize);       // Function to move an element
 virtual void Serialize(CArchive& ar);      // Serialize function for CDrawingRectangle

 // Constructor for a rectangle object
 CDrawingRectangle(const CPoint& ptStart, const CPoint& ptEnd,
  const COLORREF& crColor, const int nPenStyle,const int &PenWidth);

protected:
 CDrawingRectangle(){}        // Default constructor - should not be used
};


//=========================添加文本=============================
class CDrawingText : public CDrawingElement
{
 DECLARE_SERIAL(CDrawingText)

public:
 // Function to display a rectangle
 virtual void Draw(CDC* pDC, const CDrawingElement* pElement = 0) const;
 virtual void Move(const CSize& aSize);       // Function to move an element
 virtual void Serialize(CArchive& ar);      // Serialize function for CDrawingRectangle

 // Constructor for a rectangle object
 CDrawingText(const CPoint& ptStart, const CPoint& ptEnd,
  const CString& strText, const COLORREF& crColor);
protected:
 CDrawingText() {};
 void DrawRoundLine(CDC* pDC) const;

 CString m_strText;
 CPoint  m_ptStart;
 BOOL    m_bIsRound;   // 外围虚线
};

 

 

===================================================================================================

#include "StdAfx.h"
#include "DrawingElement.h"
#include "OurConstants.h"
#include "math.h"


IMPLEMENT_SERIAL(CDrawingElement, CObject,         VERSION_NUMBER)
IMPLEMENT_SERIAL(CDrawingCurve,   CDrawingElement, VERSION_NUMBER)
IMPLEMENT_SERIAL(CDrawingLine,    CDrawingElement, VERSION_NUMBER)
IMPLEMENT_SERIAL(CDrawingEllipse,   CDrawingElement, VERSION_NUMBER)
IMPLEMENT_SERIAL(CDrawingRectangle, CDrawingElement, VERSION_NUMBER)
IMPLEMENT_SERIAL(CDrawingText,      CDrawingElement, VERSION_NUMBER)
IMPLEMENT_SERIAL(CDrawingROUNDRECTANGLE,CDrawingElement,VERSION_NUMBER)
IMPLEMENT_SERIAL(CDrawingTRIANGLE, CDrawingElement,    VERSION_NUMBER )
IMPLEMENT_SERIAL(CDrawingRHOBMIC, CDrawingElement, VERSION_NUMBER)
IMPLEMENT_SERIAL(CDrawingLOGENGE,CDrawingElement,  VERSION_NUMBER)
IMPLEMENT_SERIAL(CDrawingRUBBER,CDrawingElement,VERSION_NUMBER)

CRect CDrawingElement::GetBoundRect(void) const
{
 CRect BoundingRect;              // Object to store bounding rectangle
 BoundingRect = m_EnclosingRect;  // 存储外围矩形

 // Increase the rectangle by the pen width
 int nOffset = (m_nPenWidth == 0)? 1:m_nPenWidth;  // 宽度至少为1;
 BoundingRect.InflateRect(nOffset, nOffset);

 return BoundingRect;
}

void CDrawingElement::Serialize(CArchive& ar)
{
 CObject::Serialize(ar);         // 调用基本函数

 if (ar.IsStoring())
 {
  ar << m_crColor              // 存储颜色,
   << m_EnclosingRect        // 外围矩形
   << m_nPenWidth            // 笔宽
   << m_nPenStyle;           // 笔形
 }
 else
 {
  ar >> m_crColor              // 恢复颜色,
   >> m_EnclosingRect        // 外围矩形
   >> m_nPenWidth            // 线宽
   >> m_nPenStyle;           // 线性
 }
}

//=========================曲线============================

CDrawingCurve::CDrawingCurve(const CPoint &FirstPoint,
               const CPoint &SecondPoint,
               const COLORREF &Color,
               const int penStyle,const int &PenWidth)
{
 m_PointList.AddTail(FirstPoint);    // Add the 1st point to the list
 m_PointList.AddTail(SecondPoint);   // Add the 2nd point to the list
 m_crColor = Color;                  // Store the color
 m_nPenWidth = PenWidth;                    // Set pen width
 m_nPenStyle = penStyle;             // Set pen style

 // Construct the enclosing rectangle assuming MM_TEXT mode
 m_EnclosingRect = CRect(FirstPoint, SecondPoint);
 m_EnclosingRect.NormalizeRect();

}

void CDrawingCurve::AddSegment(const CPoint& pt)
{
 m_PointList.AddTail(pt);                // Add the point to the end

 // Modify the enclosing rectangle for the new point
 m_EnclosingRect = CRect( min(pt.x, m_EnclosingRect.left),
  min(pt.y, m_EnclosingRect.top),
  max(pt.x, m_EnclosingRect.right),
  max(pt.y, m_EnclosingRect.bottom) );
}

void CDrawingCurve::Draw(CDC* pDC, const CDrawingElement* pElement /* = 0 */) const
{
 // Create a pen for this object and
 // initialize it to the object color and line width of 1 pixel
 CPen aPen;
 COLORREF aColor = m_crColor;            // Initialize with element color
 if (this == pElement)                
 {
  aColor = SELECT_COLOR;             // Set highlight color
 }

 if (!aPen.CreatePen(m_nPenStyle, m_nPenWidth, aColor))
 {
  // Pen creation failed. Close the program
  AfxMessageBox(_T("Pen creation failed drawing a curve"), MB_OK);
  AfxAbort();
 }

 CPen* pOldPen = pDC->SelectObject(&aPen);  // Select the pen

 // Now draw the curve
 // Get the position in the list of the first element
 POSITION aPosition = m_PointList.GetHeadPosition();
 if(aPosition)
 {
  pDC->MoveTo(m_PointList.GetNext(aPosition));
 }

 // Draw a segment for each of the following points
 while(aPosition)
 {
  pDC->LineTo(m_PointList.GetNext(aPosition));
 }

 pDC->SelectObject(pOldPen);                // Restore the old pen
}

void CDrawingCurve::Move(const CSize &aSize)
{
 m_EnclosingRect += aSize;          // Move the rectangle

 // Get the 1st element position
 POSITION aPosition = m_PointList.GetHeadPosition();

 while(aPosition)
 {
  m_PointList.GetNext(aPosition) += aSize; // Move each pt in the list
 }
}

void CDrawingCurve::Serialize(CArchive &ar)
{
 CDrawingElement::Serialize(ar);        // Call the base class function
 m_PointList.Serialize(ar);             // Serialize the list of points
}
//==================================直线======================
CDrawingLine::CDrawingLine(const CPoint& ptStart, const CPoint& ptEnd,
         const COLORREF& crColor, const int nPenStyle,const int &PenWidth)
{
 m_StartPoint = ptStart;      // Set line start point
 m_EndPoint = ptEnd;          // Set line end point
 m_crColor = crColor;         // Set line color
 m_nPenWidth = PenWidth;             // Set pen width
 m_nPenStyle = nPenStyle;     // Set pen style

 // Define the enclosing rectangle
 m_EnclosingRect = CRect(ptStart, ptEnd);
 m_EnclosingRect.NormalizeRect();
}

void CDrawingLine::Draw(CDC *pDC, const CDrawingElement *pElement/* = 0 */) const
{
 // Create a pen for this object and
 // initialize it to the object color and line width
 CPen aPen;
 COLORREF crColor = m_crColor;            // Initialize with element color
 if (this == pElement)                    // This element selected?
  crColor = SELECT_COLOR;                // Set highlight color

 if (!aPen.CreatePen(m_nPenStyle, m_nPenWidth, crColor))
 {
  // Pen creation failed. Abort the program
  AfxMessageBox(_T("Pen creation failed drawing a line"), MB_OK);
  AfxAbort();
 }

 CPen* pOldPen = pDC->SelectObject(&aPen);  // Select the pen

 // Now draw the line
 pDC->MoveTo(m_StartPoint);
 pDC->LineTo(m_EndPoint);

 pDC->SelectObject(pOldPen);                // Restore the old pen
}

void CDrawingLine::Move(const CSize &aSize)
{
 m_StartPoint += aSize;            // Move the start point
 m_EndPoint += aSize;              // and the end point
 m_EnclosingRect += aSize;         // Move the enclosing rectangle
}

void CDrawingLine::Serialize(CArchive &ar)
{
 CDrawingElement::Serialize(ar);        // Call the base class function

 if (ar.IsStoring())
 {
  ar << m_StartPoint           // Store the line start point,
   << m_EndPoint;            // and the end point
 }
 else
 {
  ar >> m_StartPoint           // Retrieve the line start point,
   >> m_EndPoint;            // and the end point
 }
}
//========================椭圆============================
// CDrawingEllipse derived class
CDrawingEllipse::CDrawingEllipse(const CPoint &ptStart, const CPoint &ptEnd,
         const COLORREF &crColor, const int nPenStyle, const int &PenWidth,
         const WORD wElement) : m_wElement(wElement)
{
 // First calculate the radius  
 long nRadius = static_cast<long>(sqrt(static_cast<double>
  ((ptEnd.x-ptStart.x)*(ptEnd.x-ptStart.x)+
  (ptEnd.y-ptStart.y)*(ptEnd.y-ptStart.y))));


 // Now calculate the rectangle enclosing
 // the circle assuming the MM_TEXT mapping mode
 if (wElement == CIRCLE)
 {
  m_EnclosingRect = CRect(ptStart.x - nRadius, ptStart.y - nRadius,
   ptStart.x + nRadius, ptStart.y + nRadius);
 }
 else
 {
  m_EnclosingRect = CRect(ptStart.x, ptStart.y,
   ptStart.x + nRadius, ptStart.y + nRadius / 2 );
 }
 m_crColor = crColor;          // Set the color for the circle or ellipse
 m_nPenWidth = PenWidth;              // Set pen width
 m_nPenStyle = nPenStyle;      // Set pen style
}

void CDrawingEllipse::Draw(CDC *pDC, const CDrawingElement *pElement/* = 0*/) const
{
 CPen aPen;
 COLORREF aColor = m_crColor;            // Initialize with element color
 if (this == pElement)                   // This element selected?
  aColor = SELECT_COLOR;                // Set highlight color

 if (!aPen.CreatePen(m_nPenStyle, m_nPenWidth, aColor))
 {
  // Pen creation failed
  AfxMessageBox(_T("Pen creation failed drawing a circle"), MB_OK);
  AfxAbort();
 }

 CPen* pOldPen = pDC->SelectObject(&aPen);  // Select the pen

 // Select a null brush
 CBrush* pOldBrush = static_cast<CBrush*>(pDC->SelectStockObject(NULL_BRUSH));

 // Now draw the circle
 pDC->Ellipse(m_EnclosingRect);

 pDC->SelectObject(pOldPen);                // Restore the old pen
 pDC->SelectObject(pOldBrush);              // Restore the old brush
}

void CDrawingEllipse::Move(const CSize &aSize)
{
 m_EnclosingRect += aSize;   // Move rectangle defining the circle or ellipse
}

void CDrawingEllipse::Serialize(CArchive &ar)
{
 CDrawingElement::Serialize(ar);        // Call the base class function

 if (ar.IsStoring())
 {
  ar << m_wElement;             // Store the element type,
 }
 else
 {
  ar >> m_wElement;           // Retrieve the element type,
 } 
}
//=============================矩形==========================
// CDrawingRectangle derived class
CDrawingRectangle::CDrawingRectangle(const CPoint &ptStart, const CPoint &ptEnd,
          const COLORREF &crColor, const int nPenStyle,const int &PenWidth)
{
 m_crColor = crColor;           // Set rectangle color
 m_nPenWidth = PenWidth;             // Set pen width
 m_nPenStyle = nPenStyle;     // Set pen style

 // Define the enclosing rectangle
 m_EnclosingRect = CRect(ptStart, ptEnd);
 m_EnclosingRect.NormalizeRect();
}

void CDrawingRectangle::Draw(CDC *pDC, const CDrawingElement *pElement) const
{
 // Create a pen for this object and
 // initialize it to the object color and line width and line style
 CPen aPen;
 COLORREF aColor = m_crColor;            // Initialize with element color
 if (this == pElement)                   // This element selected?
  aColor = SELECT_COLOR;                // Set highlight color

 if (!aPen.CreatePen(m_nPenStyle, m_nPenWidth, aColor))
 {
  // Pen creation failed
  AfxMessageBox(_T("Pen creation failed drawing a rectangle"), MB_OK);
  AfxAbort();
 }

 // Select the pen
 CPen* pOldPen = pDC->SelectObject(&aPen);  
 // Select the brush
 CBrush* pOldBrush = static_cast<CBrush*>(pDC->SelectStockObject(NULL_BRUSH));

 // Now draw the rectangle
 pDC->Rectangle(m_EnclosingRect);
 pDC->SelectObject(pOldBrush);              // Restore the old brush
 pDC->SelectObject(pOldPen);                // Restore the old pen
}

void CDrawingRectangle::Move(const CSize &aSize)
{
 m_EnclosingRect += aSize;
}

void CDrawingRectangle::Serialize(CArchive &ar)
{
 CDrawingElement::Serialize(ar);   // Call the base class function
}

//===========================添加文本============================

// CDrawingText derived class
CDrawingText::CDrawingText(const CPoint &ptStart, const CPoint &ptEnd,
         const CString &strText, const COLORREF &crColor)
         : m_bIsRound(FALSE)
{
 m_nPenWidth = 1;               // Pen width only for bounding rectangle
 m_nPenStyle = PS_SOLID;
 m_crColor = crColor;               // Set the color for the text
 m_strText = strText;             // Make a copy of the string
 m_ptStart = ptStart;
 m_ptStart.Offset(3, 3);          // Start point for string

 m_EnclosingRect = CRect(ptStart, ptEnd);
 m_EnclosingRect.NormalizeRect();
}

void CDrawingText::Draw(CDC *pDC, const CDrawingElement *pElement/* = 0*/) const
{
 COLORREF crColor(m_crColor);          // 初始化图元颜色

 if (this == pElement)
  crColor = SELECT_COLOR;          // 设置选择色

 if (m_bIsRound)
 {
  DrawRoundLine(pDC);
 }
 // Set the text color and output the text
 pDC->SetTextColor(crColor);
 pDC->TextOut(m_ptStart.x, m_ptStart.y, m_strText);
}

void CDrawingText::Move(const CSize &aSize)
{
 m_EnclosingRect += aSize;
 m_ptStart += aSize;
}

void CDrawingText::Serialize(CArchive &ar)
{
 CDrawingElement::Serialize(ar);  // 调用基类函数

 if (ar.IsStoring())
 {
  ar << m_strText          // 存储文本字符串
   << m_ptStart          // and the start point
   << m_bIsRound;        // and round dot line
 }
 else
 {
  ar >> m_strText          // 恢复
   >> m_ptStart          // and the start point
   >> m_bIsRound;        // round dot line
 }
}

void CDrawingText::DrawRoundLine(CDC* pDC) const
{
 CPen aPen;
 if (!aPen.CreatePen(PS_DOT, 1, RGB(192, 192, 192)))
 {
  // Pen creation failed
  AfxMessageBox(_T("Pen creation failed drawing a rectangle"), MB_OK);
  AfxAbort();
 }

 // Select the pen
 CPen* pOldPen = pDC->SelectObject(&aPen);  
 // Select the brush
 CBrush* pOldBrush = static_cast<CBrush*>(pDC->SelectStockObject(NULL_BRUSH));

 // Now draw the rectangle
 pDC->Rectangle(m_EnclosingRect);
 pDC->SelectObject(pOldBrush);              // Restore the old brush
 pDC->SelectObject(pOldPen);                // Restore the old pen
}

//================================圆角矩形================================
CDrawingROUNDRECTANGLE::CDrawingROUNDRECTANGLE(const CPoint &ptStart, const CPoint &ptEnd,
              const COLORREF &crColor, const int nPenStyle,const int &PenWidth
              )
{
 m_crColor = crColor;           // Set rectangle color
 m_nPenWidth = PenWidth;             // Set pen width
 m_nPenStyle = nPenStyle;     // Set pen style
 m_pointround=CPoint(50,50);

 // Define the enclosing rectangle
 m_EnclosingRect = CRect(ptStart, ptEnd);
 m_EnclosingRect.NormalizeRect();
}

void CDrawingROUNDRECTANGLE::Draw(CDC *pDC, const CDrawingElement *pElement) const
{
 // Create a pen for this object and
 // initialize it to the object color and line width and line style
 CPen aPen;
 COLORREF aColor = m_crColor;            // Initialize with element color
 if (this == pElement)                   // This element selected?
  aColor = SELECT_COLOR;                // Set highlight color

 if (!aPen.CreatePen(m_nPenStyle, m_nPenWidth, aColor))
 {
  // Pen creation failed
  AfxMessageBox(_T("Pen creation failed drawing a rounrect"), MB_OK);
  AfxAbort();
 }

 // Select the pen
 CPen* pOldPen = pDC->SelectObject(&aPen);  
 // Select the brush
 CBrush* pOldBrush = static_cast<CBrush*>(pDC->SelectStockObject(NULL_BRUSH));

 // Now draw the rectangle
 pDC->RoundRect(m_EnclosingRect,m_pointround);
 pDC->SelectObject(pOldBrush);              // Restore the old brush
 pDC->SelectObject(pOldPen);                // Restore the old pen
}

void CDrawingROUNDRECTANGLE::Move(const CSize &aSize)
{
 m_EnclosingRect += aSize;
}

void CDrawingROUNDRECTANGLE::Serialize(CArchive &ar)
{
 CDrawingElement::Serialize(ar);   // Call the base class function
}


// =========================三角形 ====================================
CDrawingTRIANGLE::CDrawingTRIANGLE(const CPoint &ptStart, const CPoint &ptEnd,
        const COLORREF &crColor, const int nPenStyle,const int &PenWidth)
{
 m_crColor = crColor;           // Set rectangle color
 m_nPenWidth = PenWidth;             // Set pen width
 m_nPenStyle = nPenStyle;     // Set pen style

 // Define the enclosing rectangle
 m_EnclosingRect = CRect(ptStart, ptEnd);
 m_EnclosingRect.NormalizeRect();
}

void CDrawingTRIANGLE::Draw(CDC *pDC, const CDrawingElement *pElement) const
{
 // Create a pen for this object and
 // initialize it to the object color and line width and line style
 CPen aPen;
 COLORREF aColor = m_crColor;            // Initialize with element color
 if (this == pElement)                   // This element selected?
  aColor = SELECT_COLOR;                // Set highlight color

 if (!aPen.CreatePen(m_nPenStyle, m_nPenWidth, aColor))
 {
  // Pen creation failed
  AfxMessageBox(_T("Pen creation failed drawing a rectangle"), MB_OK);
  AfxAbort();
 }

 // Select the pen
 CPen* pOldPen = pDC->SelectObject(&aPen);  
 // Select the brush
 CBrush* pOldBrush = static_cast<CBrush*>(pDC->SelectStockObject(NULL_BRUSH));
 CPoint pts[4];
 pts[0].x =  m_EnclosingRect.left +  m_EnclosingRect.Width()/2;
 pts[0].y =  m_EnclosingRect.top;

 pts[1].x =  m_EnclosingRect.right;
 pts[1].y =  m_EnclosingRect.top +  m_EnclosingRect.Height()/2;

 pts[2].x = pts[0].x;
 pts[2].y =  m_EnclosingRect.bottom;

 pts[3].x =  m_EnclosingRect.left;
 pts[3].y = pts[1].y;


 // Now draw the rectangle
 pDC->Polygon(pts,3);
 pDC->SelectObject(pOldBrush);              // Restore the old brush
 pDC->SelectObject(pOldPen);                // Restore the old pen
}

void  CDrawingTRIANGLE::Move(const CSize &aSize)
{
 m_EnclosingRect += aSize;
}

void  CDrawingTRIANGLE::Serialize(CArchive &ar)
{
 CDrawingElement::Serialize(ar);   // Call the base class function
}

//=====================菱形=================================
CDrawingRHOBMIC::CDrawingRHOBMIC(const CPoint &ptStart, const CPoint &ptEnd,
           const COLORREF &crColor, const int nPenStyle,const int &PenWidth)
{
 m_crColor = crColor;           // Set rectangle color
 m_nPenWidth = PenWidth;             // Set pen width
 m_nPenStyle = nPenStyle;     // Set pen style

 // Define the enclosing rectangle
 m_EnclosingRect = CRect(ptStart, ptEnd);
 m_EnclosingRect.NormalizeRect();
}

void CDrawingRHOBMIC::Draw(CDC *pDC, const CDrawingElement *pElement) const
{
 // Create a pen for this object and
 // initialize it to the object color and line width and line style
 CPen aPen;
 COLORREF aColor = m_crColor;            // Initialize with element color
 if (this == pElement)                   // This element selected?
  aColor = SELECT_COLOR;                // Set highlight color

 if (!aPen.CreatePen(m_nPenStyle, m_nPenWidth, aColor))
 {
  // Pen creation failed
  AfxMessageBox(_T("Pen creation failed drawing a rectangle"), MB_OK);
  AfxAbort();
 }

 // Select the pen
 CPen* pOldPen = pDC->SelectObject(&aPen);  
 // Select the brush
 CBrush* pOldBrush = static_cast<CBrush*>(pDC->SelectStockObject(NULL_BRUSH));
 CPoint pts[4];
 pts[0].x =  m_EnclosingRect.left +  m_EnclosingRect.Width()/2;
 pts[0].y =  m_EnclosingRect.top;

 pts[1].x =  m_EnclosingRect.right;
 pts[1].y =  m_EnclosingRect.top +  m_EnclosingRect.Height()/2;

 pts[2].x = pts[0].x;
 pts[2].y =  m_EnclosingRect.bottom;

 pts[3].x =  m_EnclosingRect.left;
 pts[3].y = pts[1].y;


 // Now draw the rectangle
 pDC->Polygon(pts,4);
 pDC->SelectObject(pOldBrush);              // Restore the old brush
 pDC->SelectObject(pOldPen);                // Restore the old pen
}

void  CDrawingRHOBMIC::Move(const CSize &aSize)
{
 m_EnclosingRect += aSize;
}

void  CDrawingRHOBMIC::Serialize(CArchive &ar)
{
 CDrawingElement::Serialize(ar);   // Call the base class function
}
//===================附属 菱形 ==============================
CDrawingLOGENGE::CDrawingLOGENGE(const CPoint &ptStart, const CPoint &ptEnd,
           const COLORREF &crColor, const int nPenStyle,const int &PenWidth)
{
 m_crColor = crColor;           //  设置菱形颜色
 m_nPenWidth = PenWidth;             //  设置笔宽
 m_nPenStyle = nPenStyle;     //  设置笔形

 // 定义一个封闭的矩形
 m_EnclosingRect = CRect(ptStart, ptEnd);
 m_EnclosingRect.NormalizeRect();
}

void CDrawingLOGENGE::Draw(CDC *pDC, const CDrawingElement *pElement) const
{
 // 为笔创建一个实体
 // 初始化 颜色,笔宽 笔形
 CPen aPen;
 COLORREF aColor = m_crColor;            // 初始化图元的颜色
 if (this == pElement)                   // This element selected?
  aColor = SELECT_COLOR;                // Set highlight color

 if (!aPen.CreatePen(m_nPenStyle, m_nPenWidth, aColor))
 {
  // Pen creation failed
  AfxMessageBox(_T("Pen creation failed drawing a rectangle"), MB_OK);
  AfxAbort();
 }

 // Select the pen
 CPen* pOldPen = pDC->SelectObject(&aPen);  
 // Select the brush
 CBrush* pOldBrush = static_cast<CBrush*>(pDC->SelectStockObject(NULL_BRUSH));
 CPoint pts[4];
 pts[0].x =  m_EnclosingRect.left +  m_EnclosingRect.Width()/2;
 pts[0].y =  m_EnclosingRect.top;

 pts[1].x =  m_EnclosingRect.right;
 pts[1].y =  m_EnclosingRect.top +  m_EnclosingRect.Height()/2;

 pts[2].x = pts[0].x;
 pts[2].y =  m_EnclosingRect.bottom;

 pts[3].x =  m_EnclosingRect.left;
 pts[3].y = pts[1].y;


 // Now draw the rectangle
 pDC->Polygon(pts,4);
  pDC->Polygon(pts,3);
 pDC->SelectObject(pOldBrush);
                                             // Restore the old brush
 pDC->SelectObject(pOldPen);                // Restore the old pen
}

void  CDrawingLOGENGE::Move(const CSize &aSize)
{
 m_EnclosingRect += aSize;
}

void  CDrawingLOGENGE::Serialize(CArchive &ar)
{
 CDrawingElement::Serialize(ar);   // Call the base class function
}

//==========================橡皮擦=========================
CDrawingRUBBER::CDrawingRUBBER (const CPoint &FirstPoint,
        const CPoint &SecondPoint,
        const COLORREF &Color,
        const int penStyle)
{
 m_PointList.AddTail(FirstPoint);    // Add the 1st point to the list
 m_PointList.AddTail(SecondPoint);   // Add the 2nd point to the list
 m_crColor = WHITE;                 
 m_nPenWidth = 50;                    // Set pen width
 m_nPenStyle = penStyle;             // Set pen style

 // Construct the enclosing rectangle assuming MM_TEXT mode
 m_EnclosingRect = CRect(FirstPoint, SecondPoint);
 m_EnclosingRect.NormalizeRect();

}

void CDrawingRUBBER::AddSegment(const CPoint& pt)
{
 m_PointList.AddTail(pt);                // Add the point to the end

 // Modify the enclosing rectangle for the new point
 m_EnclosingRect = CRect( min(pt.x, m_EnclosingRect.left),
  min(pt.y, m_EnclosingRect.top),
  max(pt.x, m_EnclosingRect.right),
  max(pt.y, m_EnclosingRect.bottom) );
}

void CDrawingRUBBER::Draw(CDC* pDC, const CDrawingElement* pElement /* = 0 */) const
{
 // Create a pen for this object and
 // initialize it to the object color and line width of 1 pixel
 CPen aPen;
 COLORREF aColor = m_crColor;            // Initialize with element color
 if (this == pElement)                
 {
  aColor = SELECT_COLOR;             // Set highlight color
 }

 if (!aPen.CreatePen(m_nPenStyle, m_nPenWidth, aColor))
 {
  // Pen creation failed. Close the program
  AfxMessageBox(_T("Pen creation failed drawing a curve"), MB_OK);
  AfxAbort();
 }

 CPen* pOldPen = pDC->SelectObject(&aPen);  // Select the pen

 // Now draw the curve
 // Get the position in the list of the first element
 POSITION aPosition = m_PointList.GetHeadPosition();
 if(aPosition)
 {
  pDC->MoveTo(m_PointList.GetNext(aPosition));
 }

 // Draw a segment for each of the following points
 while(aPosition)
 {
  pDC->LineTo(m_PointList.GetNext(aPosition));
 }

 pDC->SelectObject(pOldPen);                // Restore the old pen
}

void CDrawingRUBBER::Move(const CSize &aSize)
{
 m_EnclosingRect += aSize;          // Move the rectangle

 // Get the 1st element position
 POSITION aPosition = m_PointList.GetHeadPosition();

 while(aPosition)
 {
  m_PointList.GetNext(aPosition) += aSize; // Move each pt in the list
 }
}

void CDrawingRUBBER::Serialize(CArchive &ar)
{
 CDrawingElement::Serialize(ar);        // Call the base class function
 m_PointList.Serialize(ar);             // Serialize the list of points
}
 

 运行效果:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值