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

📄 mouseview.cpp

📁 VC程序设计技巧与实例(2)关于窗口和桌面系统、文件和系统操作、消息影射的原代码
💻 CPP
字号:
// MouseView.cpp : implementation of the CMouseView class
//

#include "stdafx.h"
#include "Mouse.h"

#include "MouseDoc.h"
#include "MouseView.h"
#include "Line.h"

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

/////////////////////////////////////////////////////////////////////////////
// CMouseView

IMPLEMENT_DYNCREATE(CMouseView, CView)

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

/////////////////////////////////////////////////////////////////////////////
// CMouseView construction/destruction

CMouseView::CMouseView()
{
	// TODO: add construction code here
}

CMouseView::~CMouseView()
{
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CMouseView drawing

void CMouseView::OnDraw(CDC* pDC)
{
	CMouseDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
	POSITION  pos = pDoc->m_LineList.GetHeadPosition();
	while (pos != NULL)
	{
		CLine*  pLine = pDoc->m_LineList.GetNext(pos);
		pLine->Draw(pDC);
	}
}

/////////////////////////////////////////////////////////////////////////////
// CMouseView printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CMouseView diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CMouseView message handlers

void CMouseView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
/*	CClientDC  dc(this);	//获取客户区设备环境
	//在视图区输出文本“鼠标左键被按下”
	dc.TextOut(100, 100, "鼠标左键被按下!");
	
	if (nFlags & MK_SHIFT)
	{
		//检查在按下鼠标左键的同时,Shift键是否被按下
		dc.TextOut(100, 150, "Shift键被按下!");
	}

	if (nFlags & MK_CONTROL)
	{
		//检查在按下鼠标左键的同时,Ctrl键是否被按下
		dc.TextOut(100, 200, "Ctrl键被按下!");
	}*/
	m_pLine = GetDocument()->NewLine();
	m_pLine->SetStartPnt(point);
	SetCapture();		//捕捉鼠标
	SetCursor(LoadCursor(NULL, IDC_CROSS));//设置鼠标形状为十字
	m_ptPrev = point;	//保留直线段的起点

	CView::OnLButtonDown(nFlags, point);
}

void CMouseView::OnLButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	if (GetCapture() != this)
		return;

	CClientDC  dc(this);

	dc.MoveTo(m_ptPrev);
	dc.LineTo(point);	//绘制
	m_pLine->SetEndPnt(point);

	ReleaseCapture();	//释放鼠标
	SetCursor(LoadCursor(NULL, IDC_ARROW));

	CView::OnLButtonUp(nFlags, point);
}

⌨️ 快捷键说明

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