MOUSEDRAWTESTVIEW.CPP
上传用户:cjd055
上传日期:2013-04-01
资源大小:608k
文件大小:5k
- // MouseDrawtestView.cpp : implementation of the CMouseDrawtestView class
- //
- #include "stdafx.h"
- #include "MouseDrawtest.h"
- #include "MouseDrawtestDoc.h"
- #include "MouseDrawtestView.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CMouseDrawtestView
- IMPLEMENT_DYNCREATE(CMouseDrawtestView, CScrollView)
- BEGIN_MESSAGE_MAP(CMouseDrawtestView, CScrollView)
- //{{AFX_MSG_MAP(CMouseDrawtestView)
- ON_WM_LBUTTONDOWN()
- ON_WM_MOUSEMOVE()
- ON_WM_LBUTTONUP()
- ON_WM_SETCURSOR()
- //}}AFX_MSG_MAP
- // Standard printing commands
- ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CMouseDrawtestView construction/destruction
- CMouseDrawtestView::CMouseDrawtestView()
- {
- // TODO: add construction code here
- m_Drawing=FALSE;
- m_Cursor=IDC_MYARROW;
- m_DrawOver=FALSE;
- }
- CMouseDrawtestView::~CMouseDrawtestView()
- {
- }
- BOOL CMouseDrawtestView::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- return CScrollView::PreCreateWindow(cs);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMouseDrawtestView drawing
- void CMouseDrawtestView::OnDraw(CDC* pDC)
- {
- CMouseDrawtestDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- // TODO: add draw code for native data here
- if(m_Drawing)
- {
- pDC->SetROP2(R2_NOT);
- pDC->SelectObject(GetStockObject(NULL_BRUSH));
- pDC->Rectangle(m_Rect);
- return;
- }
- if(m_DrawOver)
- {
- pDC->SelectObject(GetStockObject(NULL_BRUSH));
- pDC->Rectangle(m_Rect);
- m_DrawOver=FALSE;
- return;
- }
- pDC->SelectObject(GetStockObject(NULL_BRUSH));
- pDC->Rectangle(m_Rect);
- }
- void CMouseDrawtestView::OnInitialUpdate()
- {
- CScrollView::OnInitialUpdate();
- CSize sizeTotal;
- // TODO: calculate the total size of this view
- sizeTotal.cx = sizeTotal.cy = 100;
- SetScrollSizes(MM_TEXT, sizeTotal);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMouseDrawtestView printing
- BOOL CMouseDrawtestView::OnPreparePrinting(CPrintInfo* pInfo)
- {
- // default preparation
- return DoPreparePrinting(pInfo);
- }
- void CMouseDrawtestView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add extra initialization before printing
- }
- void CMouseDrawtestView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add cleanup after printing
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMouseDrawtestView diagnostics
- #ifdef _DEBUG
- void CMouseDrawtestView::AssertValid() const
- {
- CScrollView::AssertValid();
- }
- void CMouseDrawtestView::Dump(CDumpContext& dc) const
- {
- CScrollView::Dump(dc);
- }
- CMouseDrawtestDoc* CMouseDrawtestView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMouseDrawtestDoc)));
- return (CMouseDrawtestDoc*)m_pDocument;
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CMouseDrawtestView message handlers
- void CMouseDrawtestView::OnLButtonDown(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- m_Rect.top=point.y;
- m_Rect.left=point.x;
- m_Rect.right=point.x;
- m_Rect.bottom=point.y;
- Invalidate();
- SetCapture();
- SetCursor(AfxGetApp()->LoadCursor(IDC_MYCROSS));
- // m_Cursor=IDC_MYCROSS;
- m_Drawing=TRUE;
- CScrollView::OnLButtonDown(nFlags, point);
- }
- void CMouseDrawtestView::OnMouseMove(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- if(m_Drawing)
- {
- CSize sizeTotal;
- // TODO: calculate the total size of this view
- sizeTotal.cx = point.x+20;
- sizeTotal.cy = point.y+20;
- SetScrollSizes(MM_TEXT, sizeTotal);
- SetCursor(AfxGetApp()->LoadCursor(IDC_MYCROSS));
- // m_Cursor=IDC_MYCROSS;
- //擦除原有矩形:
- Invalidate();
- m_Rect.right=point.x;
- m_Rect.bottom=point.y;
- //重绘矩形:
- Invalidate();
- }
- CScrollView::OnMouseMove(nFlags, point);
- }
- void CMouseDrawtestView::OnLButtonUp(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- if(m_Drawing)
- {
- Invalidate();
- m_Rect.right=point.x;
- m_Rect.bottom=point.y;
- ReleaseCapture();
- m_Cursor=IDC_MYARROW;
- m_Drawing=FALSE;
- m_DrawOver=TRUE;
- Invalidate();
- }
- CScrollView::OnLButtonUp(nFlags, point);
- }
- BOOL CMouseDrawtestView::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
- {
- // TODO: Add your message handler code here and/or call default
- HCURSOR hc=AfxGetApp()->LoadCursor(m_Cursor);
- SetCursor(hc);
- return TRUE;
- // return CScrollView::OnSetCursor(pWnd, nHitTest, message);
- }