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

📄 sdocdemoview.cpp

📁 VC++6开发指南的源代码第7章-第11章
💻 CPP
字号:
// SDocDemoView.cpp : implementation of the CSDocDemoView class
//

#include "stdafx.h"
#include "SDocDemo.h"

#include "SDocDemoDoc.h"
#include "SDocDemoView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CSDocDemoView

IMPLEMENT_DYNCREATE(CSDocDemoView, CView)

BEGIN_MESSAGE_MAP(CSDocDemoView, CView)
	//{{AFX_MSG_MAP(CSDocDemoView)
	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()

/////////////////////////////////////////////////////////////////////////////
// CSDocDemoView construction/destruction

CSDocDemoView::CSDocDemoView()
{
	// TODO: add construction code here
	m_bDraw=false;
	m_Hcursor=AfxGetApp()->LoadStandardCursor(IDC_CROSS);//载入十字光标
}

CSDocDemoView::~CSDocDemoView()
{
}

BOOL CSDocDemoView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs
	cs.lpszClass=AfxRegisterWndClass( CS_VREDRAW | CS_HREDRAW,
      ::LoadCursor(NULL, IDC_ARROW),(HBRUSH)::GetStockObject(LTGRAY_BRUSH),0);//设置窗口背景为浅灰色
	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CSDocDemoView drawing

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

/////////////////////////////////////////////////////////////////////////////
// CSDocDemoView printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CSDocDemoView diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CSDocDemoView message handlers

void CSDocDemoView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	SetCursor(m_Hcursor);									//使用新光标
	m_bDraw=true;//进入绘图状态
	m_pOld=point;
	SetCapture();//捕捉鼠标
	CRect rect;
	GetClientRect(&rect);//获取客户窗口矩形区域
	ClientToScreen(&rect);//转换为屏幕坐标
	ClipCursor(rect);//限定鼠标不能移出客户窗口
	CView::OnLButtonDown(nFlags, point);
}

void CSDocDemoView::OnLButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	m_bDraw=false;//取消绘图状态
	ReleaseCapture();//释放鼠标捕捉
	ClipCursor(NULL);//取消鼠标区域的限制
	CView::OnLButtonUp(nFlags, point);
}

void CSDocDemoView::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default	
	if(m_bDraw)
	{
		CClientDC dc(this);//获取客户窗口DC
		dc.MoveTo(m_pOld);//绘图
		dc.LineTo(point);
		m_pOld=point;		
	}
	CView::OnMouseMove(nFlags, point);
}

⌨️ 快捷键说明

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