您的位置:首页 > 其它

MFC 涂鸦板

2012-02-13 18:15 63 查看
// 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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息