📄 lineview.cpp
字号:
// LineView.cpp : implementation of the CLineView class
//
#include "stdafx.h"
#include "Line.h"
#include "LineDoc.h"
#include "LineView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CLineView
IMPLEMENT_DYNCREATE(CLineView, CView)
BEGIN_MESSAGE_MAP(CLineView, CView)
//{{AFX_MSG_MAP(CLineView)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
ON_COMMAND(IDR_DRAW_LINE, OnDrawLine)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CLineView construction/destruction
CLineView::CLineView()
{
m_bLine=false;
// TODO: add construction code here
}
CLineView::~CLineView()
{
}
BOOL CLineView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CLineView drawing
void CLineView::OnDraw(CDC* pDC)
{
CLineDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CLineView printing
BOOL CLineView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CLineView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CLineView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CLineView diagnostics
#ifdef _DEBUG
void CLineView::AssertValid() const
{
CView::AssertValid();
}
void CLineView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CLineDoc* CLineView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CLineDoc)));
return (CLineDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CLineView message handlers
void CLineView::OnLButtonDown(UINT nFlags, CPoint point)
{
if(m_bLine)
{
m_StartPoint=point;
m_LastEndPoint=point;
SetCapture();
}
// TODO: Add your message handler code here and/or call default
CView::OnLButtonDown(nFlags, point);
}
void CLineView::OnLButtonUp(UINT nFlags, CPoint point)
{
CClientDC dc(this);
if(m_bLine&&(GetCapture()==this))
{
ReleaseCapture();
dc.MoveTo(m_StartPoint);
dc.LineTo(point);
}
// TODO: Add your message handler code here and/or call default
CView::OnLButtonUp(nFlags, point);
}
void CLineView::OnMouseMove(UINT nFlags, CPoint point)
{
CClientDC dc(this);
if(m_bLine&&(nFlags&&MK_LBUTTON))
{
int nDrawmode=dc.GetROP2();
dc.SetROP2(R2_NOT);
dc.MoveTo(m_StartPoint);
dc.LineTo(m_LastEndPoint);
dc.SetROP2(nDrawmode);
dc.MoveTo(m_StartPoint);
dc.LineTo(point);
m_LastEndPoint=point;
}
// TODO: Add your message handler code here and/or call default
// CView::OnMouseMove(nFlags, point);
}
void CLineView::OnDrawLine()
{m_bLine=true;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -