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

📄 mousedemo2view.cpp

📁 < VC++编程宝典>>配套源代码, 对于想精通VC++的朋友很有帮助!
💻 CPP
字号:
// MouseDemo2View.cpp : implementation of
// the CMouseDemo2View class
//

#include "stdafx.h"
#include "MouseDemo2.h"

#include "MouseDemo2Doc.h"
#include "MouseDemo2View.h"

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

/////////////////////////////////////////////////////////////////////////////
// CMouseDemo2View

IMPLEMENT_DYNCREATE(CMouseDemo2View, CView)

BEGIN_MESSAGE_MAP(CMouseDemo2View, CView)
	//{{AFX_MSG_MAP(CMouseDemo2View)
	ON_WM_SETCURSOR()
	ON_WM_MOUSEMOVE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMouseDemo2View construction/destruction

CMouseDemo2View::CMouseDemo2View()
{

	// Keep a list of the cursor IDs that
	// we'll load in.
	static char *szCursor[] = {
		IDC_ARROW, IDC_IBEAM, IDC_WAIT,
		IDC_CROSS, IDC_UPARROW, IDC_SIZENWSE,
		IDC_SIZENESW, IDC_SIZEWE, IDC_SIZENS,
		IDC_SIZEALL, IDC_NO, IDC_APPSTARTING,
		IDC_HELP, IDC_ARROW, IDC_ARROW, IDC_ARROW };

	// Load the cursors.
	for( int i=0; i<16; i++ )
		m_hCursor[i] =
			::LoadCursor( NULL, szCursor[i] );

}

CMouseDemo2View::~CMouseDemo2View()
{
}

BOOL CMouseDemo2View::PreCreateWindow(CREATESTRUCT& cs)
{
	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CMouseDemo2View drawing

void CMouseDemo2View::OnDraw(CDC* pDC)
{
	CMouseDemo2Doc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
}

/////////////////////////////////////////////////////////////////////////////
// CMouseDemo2View diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CMouseDemo2View message handlers

BOOL CMouseDemo2View::OnSetCursor(CWnd* pWnd, UINT nHitTest,
	UINT message) 
{

	// See if this is a HTCLIENT
	// hit test.
	if( nHitTest == HTCLIENT ){

		// Get the mouse position. This
		// will be in terms of the
		// entire screen.
		POINT pt;
		GetCursorPos( &pt );

		// Convert the coordinates to
		// client rectangle coordinates.
		ScreenToClient( &pt );

		// Call the function that we created
		// which gets the cursor region.
		int nCursor = GetCursorRegion( &pt );

		// Set the window cursor.
		::SetCursor( m_hCursor[nCursor] );

		// Return indicating that we responded
		// to this message.
		return( TRUE );
		}

	// Call the default OnSetCursor() function.
	return CView::OnSetCursor(pWnd, nHitTest, message);
}

int CMouseDemo2View::GetCursorRegion( POINT *lpPt )
{

	// We'll need the client
	// rectangle so that we can
	// calculate the cursor region.
	// It''ll be an x value from 0-3
	// and a y value from 0-3.
	RECT Rect;
	GetClientRect( &Rect );

	// Divide the client rectangle width
	// by four to obtain the x region
	// index.
	int x =
		( lpPt->x * 4 ) / Rect.right;
	if( x > 3 ) x = 3;


	// Divide the client rectangle height
	// by four to obtain the y region
	// index.
	int y =
		( lpPt->y * 4 ) / Rect.bottom;
	if( y > 3 ) y = 3;

	// Return the index. It'll be a value
	// from 0-15.
	return( y * 4 + x );

}

void CMouseDemo2View::OnMouseMove(UINT nFlags, CPoint point) 
{
	
	// Keep a list of the cursor names
	// so that we can display them
	// in the client window.
	static CString strCursor[] = {
		"IDC_ARROW", "IDC_IBEAM", "IDC_WAIT",
		"IDC_CROSS", "IDC_UPARROW", "IDC_SIZENWSE",
		"IDC_SIZENESW", "IDC_SIZEWE", "IDC_SIZENS",
		"IDC_SIZEALL", "IDC_NO", "IDC_APPSTARTING",
		"IDC_HELP", "IDC_ARROW", "IDC_ARROW",
		"IDC_ARROW" };

	// Get the cursor region. This
	// will be a value from 0-15 and
	// will correspond to the 16
	// cursors we loaded.
	int nCursor =
		GetCursorRegion( &point );

	// Get a DC to the client window
	// so that we can draw.
	CClientDC ClientDC( this );

	CString strInfo;

	// Format a string.
	strInfo = "Cursor:" +
		strCursor[nCursor] +
		"           ";

	// Draw the string to the client window.
	ClientDC.TextOut( 0, 0,
		strInfo, strInfo.GetLength() );

	// Call the default OnMouseMove() function.
	CView::OnMouseMove(nFlags, point);
}

⌨️ 快捷键说明

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