DrawLine.cpp
资源名称:DrawSys.zip [点击查看]
上传用户:mosfetic
上传日期:2022-06-16
资源大小:4612k
文件大小:3k
源码类别:
GDI/图象编程
开发平台:
Visual C++
- // DrawLine.cpp: implementation of the CDrawLine class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "DrawSys.h"
- #include "DrawLine.h"
- #include "ViewProperty.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- IMPLEMENT_SERIAL(CDrawLine, CObject, 1)
- CDrawLine::CDrawLine()
- {
- m_ptFirst.x = m_ptFirst.y = 0;
- m_ptSecond.x = m_ptSecond.y = 0;
- m_ptTemp.x = m_ptTemp.y = 0;
- m_bStart = FALSE;
- }
- CDrawLine::~CDrawLine()
- {
- }
- void CDrawLine::Draw(CDC* pDC)
- {
- pDC->MoveTo(m_ptFirst);
- pDC->LineTo(m_ptSecond);
- }
- void CDrawLine::OnMouseMove(CDC* pDC, UINT nFlags, CPoint point)
- {
- int iDrawMode = 0;
- if(m_bStart)
- {
- if(pDC)
- {
- iDrawMode = pDC->SetROP2(R2_NOTXORPEN);
- pDC->MoveTo(m_ptFirst);
- pDC->LineTo(m_ptTemp);
- m_ptTemp = point;
- pDC->MoveTo(m_ptFirst);
- pDC->LineTo(m_ptTemp);
- pDC->SetROP2(iDrawMode);
- }
- }
- }
- void CDrawLine::OnLButtonDown(CDC* pDC, UINT nFlags, CPoint point)
- {
- m_ptFirst = point;
- m_ptTemp = point;
- m_bStart = TRUE;
- }
- BOOL CDrawLine::OnLButtonUp(CDC* pDC, UINT nFlags, CPoint point)
- {
- int iDrawMode = 0;
- if(m_bStart)
- {
- if(pDC)
- {
- iDrawMode = pDC->SetROP2(R2_NOTXORPEN);
- pDC->MoveTo(m_ptFirst);
- pDC->LineTo(m_ptTemp);
- m_ptSecond = point;
- m_ptTemp = point;
- pDC->SetROP2(R2_COPYPEN);
- Draw(pDC);
- pDC->SetROP2(iDrawMode);
- }
- m_bStart = FALSE;
- }
- return (m_ptFirst!=m_ptSecond);
- }
- void CDrawLine::Serialize(CArchive& ar)
- {
- if (ar.IsStoring())
- {
- // TODO: add storing code here
- ar << m_ptFirst << m_ptSecond;
- }
- else
- {
- // TODO: add loading code here
- ar >> m_ptFirst >> m_ptSecond;
- }
- }
- BOOL CDrawLine::PtInShape(CPoint point)
- {
- CRect rcDraw;
- rcDraw.left = MIN(m_ptFirst.x, m_ptSecond.x);
- rcDraw.top = MIN(m_ptFirst.y, m_ptSecond.y);
- rcDraw.right = MAX(m_ptFirst.x, m_ptSecond.x);
- rcDraw.bottom = MAX(m_ptFirst.y, m_ptSecond.y);
- return rcDraw.PtInRect(point);
- }
- void CDrawLine::ShowProperty()
- {
- CRect rcDraw;
- CString strID;
- CString strTime;
- CViewProperty dlg;
- rcDraw.left = MIN(m_ptFirst.x, m_ptSecond.x);
- rcDraw.top = MIN(m_ptFirst.y, m_ptSecond.y);
- rcDraw.right = MAX(m_ptFirst.x, m_ptSecond.x);
- rcDraw.bottom = MAX(m_ptFirst.y, m_ptSecond.y);
- dlg.m_strType = "直线";
- MyFormatString(dlg.m_strID, m_iID);
- dlg.m_iLength = rcDraw.Width();
- dlg.m_iWidth = rcDraw.Height();
- dlg.m_strTime = m_tmCreate.Format("%Y - %m - %d");
- dlg.DoModal();
- }