⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mydrawlineview.cpp

📁 一个简单的vc++案例
💻 CPP
字号:
// MyDrawLineView.cpp : implementation of the CMyDrawLineView class
//

#include "stdafx.h"
#include "MyDrawLine.h"

#include "MyDrawLineDoc.h"
#include "MyDrawLineView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMyDrawLineView

IMPLEMENT_DYNCREATE(CMyDrawLineView, CView)

BEGIN_MESSAGE_MAP(CMyDrawLineView, CView)
	//{{AFX_MSG_MAP(CMyDrawLineView)
	ON_WM_LBUTTONDOWN()
	ON_WM_LBUTTONUP()
	ON_WM_MOUSEMOVE()
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CMyDrawLineView construction/destruction

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

}

CMyDrawLineView::~CMyDrawLineView()
{
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CMyDrawLineView drawing

void CMyDrawLineView::OnDraw(CDC* pDC)
{
	CMyDrawLineDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CMyDrawLineView printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CMyDrawLineView diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CMyDrawLineView message handlers

void CMyDrawLineView::OnLButtonDown(UINT nFlags, CPoint point) 
{
SetCapture();
m_ptStart=m_ptEnd=point;

	// TODO: Add your message handler code here and/or call default
	
	CView::OnLButtonDown(nFlags, point);
}

void CMyDrawLineView::OnLButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
if(GetCapture()!=this)
return;	
CClientDC dc(this);
m_ptEnd=point;	
dc.MoveTo(m_ptStart);
dc.LineTo(m_ptEnd);
ReleaseCapture();
	CView::OnLButtonUp(nFlags, point);
}

void CMyDrawLineView::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
if(GetCapture()!=this)
return;
CClientDC dc(this);
CPen newPen(1,1,RGB(255,0,0));
CPen* oldPen=dc.SelectObject(&newPen);
int noldMode=dc.SetROP2(R2_NOTXORPEN);
dc.MoveTo(m_ptStart);
dc.LineTo(m_ptEnd);
m_ptEnd=point;	
dc.MoveTo(m_ptStart);
dc.LineTo(m_ptEnd);
dc.SelectObject(oldPen);
dc.SetROP2(noldMode);
	CView::OnMouseMove(nFlags, point);
}

void CMyDrawLineView::Serialize(CArchive& ar) 
{
	if (ar.IsStoring())
	{	// storing code
	}
	else
	{	// loading code
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -