📄 mousedemoview.cpp
字号:
// MouseDemoView.cpp : implementation of the CMouseDemoView class
//
#include "stdafx.h"
#include "MouseDemo.h"
#include "MouseDemoDoc.h"
#include "MouseDemoView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMouseDemoView
IMPLEMENT_DYNCREATE(CMouseDemoView, CView)
BEGIN_MESSAGE_MAP(CMouseDemoView, CView)
//{{AFX_MSG_MAP(CMouseDemoView)
ON_WM_LBUTTONDOWN()
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONUP()
ON_COMMAND(ID_LINE, OnLine)
ON_COMMAND(ID_CIRCLE, OnCircle)
ON_COMMAND(ID_RECTANGLE, OnRectangle)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMouseDemoView construction/destruction
CMouseDemoView::CMouseDemoView()
{
m_dragging=0;
m_shape=1;
// TODO: add construction code here
}
CMouseDemoView::~CMouseDemoView()
{
}
BOOL CMouseDemoView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMouseDemoView drawing
void CMouseDemoView::OnDraw(CDC* pDC)
{
CMouseDemoDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CMouseDemoView printing
BOOL CMouseDemoView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CMouseDemoView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CMouseDemoView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CMouseDemoView diagnostics
#ifdef _DEBUG
void CMouseDemoView::AssertValid() const
{
CView::AssertValid();
}
void CMouseDemoView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CMouseDemoDoc* CMouseDemoView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMouseDemoDoc)));
return (CMouseDemoDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMouseDemoView message handlers
void CMouseDemoView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_dragging=1;
m_pointorg=point;
m_pointold=point;
CView::OnLButtonDown(nFlags, point);
}
void CMouseDemoView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(m_dragging)
{
CClientDC dc(this);
dc.SetROP2(R2_NOT);
dc.MoveTo(m_pointorg);
m_dragging=0;
switch(m_shape)
{
case 1:
dc.LineTo(m_pointold);
dc.MoveTo(m_pointorg);
dc.LineTo(point);
break;
case 2:
dc.SelectStockObject(NULL_BRUSH);
dc.Rectangle(m_pointorg.x,m_pointorg.y,m_pointold.x,m_pointold.y);
dc.MoveTo(m_pointorg);
dc.Rectangle(m_pointorg.x,m_pointorg.y,point.x,point.y);
break;
case 3:
dc.SelectStockObject(NULL_BRUSH);
dc.Ellipse(m_pointorg.x,m_pointorg.y,m_pointold.x,m_pointold.y);
dc.MoveTo(m_pointorg);
dc.Ellipse(m_pointorg.x,m_pointorg.y,point.x,point.y);
break;
}
m_pointold=point;
}
CView::OnMouseMove(nFlags, point);
}
void CMouseDemoView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_dragging=0;
CClientDC dc(this);
dc.SetROP2(R2_NOT);
dc.MoveTo(m_pointorg);
switch(m_shape)
{
case 1:
dc.LineTo(m_pointold);
dc.MoveTo(m_pointorg);
dc.LineTo(point);
break;
case 2:
dc.SelectStockObject(NULL_BRUSH);
dc.Rectangle(m_pointorg.x,m_pointorg.y,m_pointold.x,m_pointold.y);
dc.MoveTo(m_pointorg);
dc.Rectangle(m_pointorg.x,m_pointorg.y,point.x,point.y);
break;
case 3:
dc.SelectStockObject(NULL_BRUSH);
dc.Ellipse(m_pointorg.x,m_pointorg.y,m_pointold.x,m_pointold.y);
dc.MoveTo(m_pointorg);
dc.Ellipse(m_pointorg.x,m_pointorg.y,point.x,point.y);
break;
}
CView::OnLButtonUp(nFlags, point);
}
void CMouseDemoView::OnLine()
{
// TODO: Add your command handler code here
m_shape=1;
}
void CMouseDemoView::OnCircle()
{
// TODO: Add your command handler code here
m_shape=3;
}
void CMouseDemoView::OnRectangle()
{
// TODO: Add your command handler code here
m_shape=2;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -