MFC 涂鸦板

// mfclab6View.h : interface of the Cmfclab6View class
//




#pragma once




class Cmfclab6View : public CView
{
protected: // create from serialization only
Cmfclab6View();
DECLARE_DYNCREATE(Cmfclab6View)


// Attributes
public:
Cmfclab6Doc* GetDocument() const;
CPoint prevPoint;
CPen* pen;
bool isDrawing;
// Operations
public:


// Overrides
public:
virtual void OnDraw(CDC* pDC);  // overridden to draw this view
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
protected:
virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);


// Implementation
public:
virtual ~Cmfclab6View();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif


protected:
afx_msg void OnLButtonDown(UINT flags,CPoint p);
afx_msg void OnLButtonUp(UINT flags,CPoint p);
afx_msg void OnMouseMove(UINT flags,CPoint p);
// Generated message map functions
protected:
DECLARE_MESSAGE_MAP()
};


#ifndef _DEBUG  // debug version in mfclab6View.cpp
inline Cmfclab6Doc* Cmfclab6View::GetDocument() const
   { return reinterpret_cast<Cmfclab6Doc*>(m_pDocument); }
#endif



// mfclab6View.cpp : implementation of the Cmfclab6View class
//


#include "stdafx.h"
#include "mfclab6.h"


#include "mfclab6Doc.h"
#include "mfclab6View.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#endif




// Cmfclab6View


IMPLEMENT_DYNCREATE(Cmfclab6View, CView)


BEGIN_MESSAGE_MAP(Cmfclab6View, CView)
// 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)
//
ON_WM_LBUTTONDOWN(UINT flags,CPoint p)
ON_WM_MOUSEMOVE(UINT flags,CPoint p)
ON_WM_LBUTTONUP(UINT flags,CPoint p)


END_MESSAGE_MAP()


// Cmfclab6View construction/destruction


Cmfclab6View::Cmfclab6View()
{
// TODO: add construction code here


this->isDrawing = false;
this->pen = new CPen(PS_SOLID,1,1);
}


Cmfclab6View::~Cmfclab6View()
{
}


BOOL Cmfclab6View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
//  the CREATESTRUCT cs


return CView::PreCreateWindow(cs);
}


// Cmfclab6View drawing


void Cmfclab6View::OnDraw(CDC* pDC)
{






// TODO: add draw code for native data here
}




// Cmfclab6View printing


BOOL Cmfclab6View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}


void Cmfclab6View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}


void Cmfclab6View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}


//


void Cmfclab6View::OnLButtonDown(UINT F,CPoint p){
this->prevPoint = p;
SetCapture();
this->isDrawing = true;
}


void Cmfclab6View::OnLButtonUp(UINT F,CPoint p){  

if(GetCapture()!=this){
return;
}
CClientDC dc(this);
CPen* poldPen = dc.SelectObject(this->pen);
dc.MoveTo(this->prevPoint.x,this->prevPoint.y);
dc.LineTo(p.x,p.y);
this->prevPoint = p;
this->isDrawing = false;
ReleaseCapture();
}


void Cmfclab6View::OnMouseMove(UINT F,CPoint p){
if(this->isDrawing){
CClientDC dc(this);
CPen* poldPen = dc.SelectObject(this->pen);
dc.MoveTo(this->prevPoint.x,this->prevPoint.y);
dc.LineTo(p.x,p.y);
this->prevPoint = p;
}
}


///


// Cmfclab6View diagnostics


#ifdef _DEBUG
void Cmfclab6View::AssertValid() const
{
CView::AssertValid();
}


void Cmfclab6View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}


Cmfclab6Doc* Cmfclab6View::GetDocument() const // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(Cmfclab6Doc)));
return (Cmfclab6Doc*)m_pDocument;
}
#endif //_DEBUG




// Cmfclab6View message handlers


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值