📄 drwview.cpp
字号:
// drwView.cpp : implementation of the CDrwView class
//
#include "stdafx.h"
#include "drw.h"
#include "drwDoc.h"
#include "drwView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDrwView
IMPLEMENT_DYNCREATE(CDrwView, CView)
BEGIN_MESSAGE_MAP(CDrwView, CView)
//{{AFX_MSG_MAP(CDrwView)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
ON_COMMAND(ID_LINE, OnLine)
ON_UPDATE_COMMAND_UI(ID_LINE, OnUpdateLine)
ON_COMMAND(ID_CURVE, OnCurve)
ON_UPDATE_COMMAND_UI(ID_CURVE, OnUpdateCurve)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CDrwView construction/destruction
CDrwView::CDrwView()
{
// TODO: add construction code here
DrawWhat=1;
}
CDrwView::~CDrwView()
{
}
BOOL CDrwView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CDrwView drawing
void CDrwView::OnDraw(CDC* pDC)
{
CDrwDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
pDoc->DrawLine(pDC);
}
/////////////////////////////////////////////////////////////////////////////
// CDrwView printing
BOOL CDrwView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CDrwView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CDrwView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CDrwView diagnostics
#ifdef _DEBUG
void CDrwView::AssertValid() const
{
CView::AssertValid();
}
void CDrwView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CDrwDoc* CDrwView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDrwDoc)));
return (CDrwDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CDrwView message handlers
void CDrwView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
SetCapture();
point0=point1=point;
CView::OnLButtonDown(nFlags, point);
}
void CDrwView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CDrwDoc* pDoc = GetDocument();
if(GetCapture()==this)
{
ReleaseCapture();
if(DrawWhat==1) //画直线
{
CDC* pDC=GetDC();
CLine* Line=pDoc->AddLine(point0,point);
Line->Draw(pDC);
}
}
CView::OnLButtonUp(nFlags, point);
}
void CDrwView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CDrwDoc* pDoc = GetDocument();
if(GetCapture()==this)
if(DrawWhat==2) //画曲线
{
CDC* pDC=GetDC();
pDoc->AddLine(point0,point);
point0=point;
OnDraw(pDC);
}
else //画直线
{ CPen Pen1(PS_SOLID,1,RGB(255,255,255));
CPen *oldPen;
CDC* pDC=GetDC();
// //要求文档重绘
oldPen=pDC->SelectObject(&Pen1);
pDC->MoveTo(point0);
pDC->LineTo(point1);
pDC->SelectObject(oldPen);
pDC->MoveTo(point0);
pDC->LineTo(point);
OnDraw(pDC);
point1=point;
}
CView::OnMouseMove(nFlags, point);
}
void CDrwView::OnLine()
{
// TODO: Add your command handler code here
DrawWhat=1;
}
void CDrwView::OnUpdateLine(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(DrawWhat==1);
}
void CDrwView::OnCurve()
{
// TODO: Add your command handler code here
DrawWhat=2;
}
void CDrwView::OnUpdateCurve(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(DrawWhat==2);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -