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

📄 ch5demo4view.cpp

📁 零基础学Visual.C....教案PPT.随书光盘-452M.zip
💻 CPP
字号:
// Ch5Demo4View.cpp : implementation of the CCh5Demo4View class
//

#include "stdafx.h"
#include "Ch5Demo4.h"

#include "Ch5Demo4Doc.h"
#include "Ch5Demo4View.h"

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

/////////////////////////////////////////////////////////////////////////////
// CCh5Demo4View

IMPLEMENT_DYNCREATE(CCh5Demo4View, CView)

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

/////////////////////////////////////////////////////////////////////////////
// CCh5Demo4View construction/destruction

CCh5Demo4View::CCh5Demo4View()
{
	// TODO: add construction code here
	//初始化定义的变量
	fDowned=false;
	ptDown.x=0;
	ptDown.y=0;
	ptUp.x=0;
	ptUp.y=0;
}

CCh5Demo4View::~CCh5Demo4View()
{
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CCh5Demo4View drawing

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

/////////////////////////////////////////////////////////////////////////////
// CCh5Demo4View printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CCh5Demo4View diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CCh5Demo4View message handlers

void CCh5Demo4View::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	SetCapture();//捕捉鼠标
	GetClipCursor(&oldrect); 						//获取原鼠标活动的有效区域
	CRect rect1;
	GetWindowRect(&rect1);							//获取客户区窗口区域
	ClipCursor(&rect1);								//将鼠标的移动限制的客户区
	fDowned=TRUE;
	ptUp=ptDown=point;
	CView::OnLButtonDown(nFlags, point);
}

void CCh5Demo4View::DrawRect()
{
	CClientDC dc(this);//获取DC
	CRect rect;
	GetClientRect(rect);//获取客户窗口区域
	CBrush brush(RGB(255,255,255));
	dc.FillRect(rect,&brush);//填充背景色为白色
	dc.Rectangle(ptDown.x,ptDown.y,ptUp.x,ptUp.y);//绘制矩形
}

void CCh5Demo4View::OnLButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	ReleaseCapture();//释放鼠标
	ClipCursor(&oldrect);								//恢复鼠标的活动区域
	if(fDowned)
	{
		ptUp=point;
		DrawRect();//画新矩形
		fDowned=FALSE;
	}
	CView::OnLButtonUp(nFlags, point);
}

void CCh5Demo4View::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	if(fDowned)
	{
		HCURSOR cusor=AfxGetApp( )->LoadStandardCursor(IDC_CROSS);		//获取系统标准光标
		SetCursor(cusor);												//设置光标
		ptUp=point;
		DrawRect();//画新矩形
	}
	CView::OnMouseMove(nFlags, point);
}

⌨️ 快捷键说明

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