DrawFillEllipse.cpp
资源名称:DrawSys.zip [点击查看]
上传用户:mosfetic
上传日期:2022-06-16
资源大小:4612k
文件大小:4k
源码类别:
GDI/图象编程
开发平台:
Visual C++
- // DrawFillEllipse.cpp: implementation of the CDrawFillEllipse class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "DrawSys.h"
- #include "DrawFillEllipse.h"
- #include "ViewProperty.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- IMPLEMENT_SERIAL(CDrawFillEllipse, CObject, 1)
- CDrawFillEllipse::CDrawFillEllipse()
- {
- m_ptFirst.x = m_ptFirst.y = 0;
- m_ptSecond.x = m_ptSecond.y = 0;
- m_ptTemp.x = m_ptTemp.y = 0;
- m_bStart = FALSE;
- }
- CDrawFillEllipse::~CDrawFillEllipse()
- {
- }
- void CDrawFillEllipse::Draw(CDC* pDC)
- {
- CRect rcDraw;
- CBrush brush(RGB(0, 255, 0));
- HBRUSH hOldBrush = NULL;
- CPen* pPen = NULL;
- CPen* pOldPen = NULL;
- rcDraw.left = m_ptFirst.x;
- rcDraw.top = m_ptFirst.y;
- rcDraw.right = m_ptSecond.x;
- rcDraw.bottom = m_ptSecond.y;
- pPen = CPen::FromHandle((HPEN)GetStockObject(NULL_PEN));
- pOldPen = pDC->SelectObject(pPen);
- hOldBrush = (HBRUSH)pDC->SelectObject(&brush);
- pDC->Ellipse(&rcDraw);
- pDC->SelectObject(hOldBrush);
- pDC->SelectObject(pOldPen);
- brush.DeleteObject();
- }
- void CDrawFillEllipse::OnMouseMove(CDC* pDC, UINT nFlags, CPoint point)
- {
- int iDrawMode = 0;
- CRect rcDraw;
- if(m_bStart)
- {
- if(pDC)
- {
- iDrawMode = pDC->SetROP2(R2_NOTXORPEN);
- rcDraw.left = m_ptFirst.x;
- rcDraw.top = m_ptFirst.y;
- rcDraw.right = m_ptTemp.x;
- rcDraw.bottom = m_ptTemp.y;
- pDC->Ellipse(&rcDraw);
- m_ptTemp = point;
- rcDraw.right = m_ptTemp.x;
- rcDraw.bottom = m_ptTemp.y;
- pDC->Ellipse(&rcDraw);
- pDC->SetROP2(iDrawMode);
- }
- }
- }
- void CDrawFillEllipse::OnLButtonDown(CDC* pDC, UINT nFlags, CPoint point)
- {
- m_ptFirst = point;
- m_ptTemp = point;
- m_bStart = TRUE;
- }
- BOOL CDrawFillEllipse::OnLButtonUp(CDC* pDC, UINT nFlags, CPoint point)
- {
- int iDrawMode = 0;
- CRect rcDraw;
- CBrush brush(RGB(0, 255, 0));
- HBRUSH hOldBrush = NULL;
- CPen* pPen = NULL;
- HPEN hOldPen = NULL;
- if(m_bStart)
- {
- if(pDC)
- {
- iDrawMode = pDC->SetROP2(R2_NOTXORPEN);
- rcDraw.left = m_ptFirst.x;
- rcDraw.top = m_ptFirst.y;
- rcDraw.right = m_ptTemp.x;
- rcDraw.bottom = m_ptTemp.y;
- pDC->Ellipse(&rcDraw);
- m_ptSecond = point;
- m_ptTemp = point;
- 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);
- m_ptFirst.x = rcDraw.left;
- m_ptFirst.y = rcDraw.top;
- m_ptSecond.x = rcDraw.right;
- m_ptSecond.y = rcDraw.bottom;
- pDC->SetROP2(R2_COPYPEN);
- pPen = CPen::FromHandle((HPEN)GetStockObject(NULL_PEN));
- hOldPen = (HPEN)pDC->SelectObject(pPen);
- hOldBrush = (HBRUSH)pDC->SelectObject(&brush);
- Draw(pDC);
- pDC->SelectObject(hOldBrush);
- pDC->SelectObject(hOldPen);
- brush.DeleteObject();
- pDC->SetROP2(iDrawMode);
- }
- m_bStart = FALSE;
- }
- return (!rcDraw.IsRectEmpty());
- }
- void CDrawFillEllipse::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 CDrawFillEllipse::PtInShape(CPoint point)
- {
- CRect rcDraw;
- CRgn rgn;
- BOOL m_bRetVal = FALSE;
- 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);
- rgn.CreateEllipticRgnIndirect(&rcDraw);
- m_bRetVal = rgn.PtInRegion(point);
- rgn.DeleteObject();
- return m_bRetVal;
- }
- void CDrawFillEllipse::ShowProperty()
- {
- CRect rcDraw;
- CString strID;
- CString strTime;
- CViewProperty dlg;
- rcDraw.left = m_ptFirst.x;
- rcDraw.top = m_ptFirst.y;
- rcDraw.right = m_ptSecond.x;
- rcDraw.bottom = 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();
- }