DrawFillRect.cpp
资源名称:DrawSys.zip [点击查看]
上传用户:mosfetic
上传日期:2022-06-16
资源大小:4612k
文件大小:4k
源码类别:
GDI/图象编程
开发平台:
Visual C++
- // DrawFillRect.cpp: implementation of the CDrawFillRect class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "DrawSys.h"
- #include "DrawFillRect.h"
- #include "ViewProperty.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- IMPLEMENT_SERIAL(CDrawFillRect, CObject, 1)
- CDrawFillRect::CDrawFillRect()
- {
- m_ptFirst.x = m_ptFirst.y = 0;
- m_ptSecond.x = m_ptSecond.y = 0;
- m_ptTemp.x = m_ptTemp.y = 0;
- m_bStart = FALSE;
- }
- CDrawFillRect::~CDrawFillRect()
- {
- }
- void CDrawFillRect::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->Rectangle(&rcDraw);
- pDC->SelectObject(hOldBrush);
- pDC->SelectObject(pOldPen);
- brush.DeleteObject();
- }
- void CDrawFillRect::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->Rectangle(&rcDraw);
- m_ptTemp = point;
- rcDraw.right = m_ptTemp.x;
- rcDraw.bottom = m_ptTemp.y;
- pDC->Rectangle(&rcDraw);
- pDC->SetROP2(iDrawMode);
- }
- }
- }
- void CDrawFillRect::OnLButtonDown(CDC* pDC, UINT nFlags, CPoint point)
- {
- m_ptFirst = point;
- m_ptTemp = point;
- m_bStart = TRUE;
- }
- BOOL CDrawFillRect::OnLButtonUp(CDC* pDC, UINT nFlags, CPoint point)
- {
- int iDrawMode = 0;
- CRect rcDraw;
- CBrush brush(RGB(0, 255, 0));
- 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->Rectangle(&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);
- Draw(pDC);
- brush.DeleteObject();
- pDC->SetROP2(iDrawMode);
- }
- m_bStart = FALSE;
- }
- return (!rcDraw.IsRectEmpty());
- }
- void CDrawFillRect::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 CDrawFillRect::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 CDrawFillRect::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();
- }