📄 displaymousemsgview.cpp
字号:
// DisplayMouseMsgView.cpp : implementation of the CDisplayMouseMsgView class
//
#include "stdafx.h"
#include "DisplayMouseMsg.h"
#include "DisplayMouseMsgDoc.h"
#include "DisplayMouseMsgView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDisplayMouseMsgView
IMPLEMENT_DYNCREATE(CDisplayMouseMsgView, CView)
BEGIN_MESSAGE_MAP(CDisplayMouseMsgView, CView)
//{{AFX_MSG_MAP(CDisplayMouseMsgView)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
ON_WM_MOUSEWHEEL()
ON_WM_RBUTTONDOWN()
ON_WM_RBUTTONUP()
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CDisplayMouseMsgView construction/destruction
CDisplayMouseMsgView::CDisplayMouseMsgView()
{
// TODO: add construction code here
m_nCnt = 0;
m_nAction = 0;
}
CDisplayMouseMsgView::~CDisplayMouseMsgView()
{
}
BOOL CDisplayMouseMsgView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CDisplayMouseMsgView drawing
void CDisplayMouseMsgView::OnDraw(CDC* pDC)
{
CDisplayMouseMsgDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
pDC->SetBkColor(RGB(255,255,255)); // 设置背景色
pDC->SetTextColor(RGB(255,0,0)); // 设置前景色
// 在客户区显示信息
pDC->TextOut(0,
0,
_T("本程序的功能:测试用户的鼠标事件"));
// 获得当前客户区的矩形区域
CRect rc;
GetClientRect(&rc);
int centerX = (rc.left + rc.right)/2;
int centerY = (rc.top + rc.bottom)/2;
switch (m_nAction)
{
case 1:
pDC->SetBkColor(RGB(0,0,0));
pDC->SetTextColor(RGB(255,255,0));
pDC->TextOut(centerX, centerY, _T("你当前按下的是鼠标左键!"));
break;
case 2:
pDC->SetBkColor(RGB(0,255,0));
pDC->SetTextColor(RGB(0,0,255));
pDC->TextOut(centerX, centerY, _T("你当前松开的是鼠标左键!"));
break;
case 3:
pDC->SetBkColor(RGB(0,255,255));
pDC->SetTextColor(RGB(255,0,0));
pDC->TextOut(centerX, centerY, _T("你当前移动鼠标了!"));
break;
case 4:
pDC->SetBkColor(RGB(0,0,0));
pDC->SetTextColor(RGB(255,255,255));
pDC->TextOut(centerX, centerY, _T("你当前拨动鼠标滚轮了!"));
break;
case 5:
pDC->SetBkColor(RGB(0,255,255));
pDC->SetTextColor(RGB(255,0,0));
pDC->TextOut(centerX, centerY, _T("你当前按下的是鼠标右键!"));
break;
case 6:
pDC->SetBkColor(RGB(0,255,255));
pDC->SetTextColor(RGB(255,0,0));
pDC->TextOut(centerX, centerY, _T("你当前松开的是鼠标右键!"));
break;
default:
break;
}
}
/////////////////////////////////////////////////////////////////////////////
// CDisplayMouseMsgView printing
BOOL CDisplayMouseMsgView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CDisplayMouseMsgView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CDisplayMouseMsgView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CDisplayMouseMsgView diagnostics
#ifdef _DEBUG
void CDisplayMouseMsgView::AssertValid() const
{
CView::AssertValid();
}
void CDisplayMouseMsgView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CDisplayMouseMsgDoc* CDisplayMouseMsgView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDisplayMouseMsgDoc)));
return (CDisplayMouseMsgDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CDisplayMouseMsgView message handlers
void CDisplayMouseMsgView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_nAction = 1;
CPaintDC dc(this); // device context for painting
OnDraw(&dc);
Invalidate();
CView::OnLButtonDown(nFlags, point);
}
void CDisplayMouseMsgView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_nAction = 2;
CPaintDC dc(this); // device context for painting
OnDraw(&dc);
Invalidate();
CView::OnLButtonUp(nFlags, point);
}
void CDisplayMouseMsgView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_nAction = 3;
CPaintDC dc(this); // device context for painting
OnDraw(&dc);
Invalidate();
CView::OnMouseMove(nFlags, point);
}
BOOL CDisplayMouseMsgView::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
{
// TODO: Add your message handler code here and/or call default
m_nAction = 4;
CPaintDC dc(this); // device context for painting
OnDraw(&dc);
Invalidate();
return CView::OnMouseWheel(nFlags, zDelta, pt);
}
void CDisplayMouseMsgView::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_nAction = 5;
CPaintDC dc(this); // device context for painting
OnDraw(&dc);
Invalidate();
CView::OnRButtonDown(nFlags, point);
}
void CDisplayMouseMsgView::OnRButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_nAction = 6;
CPaintDC dc(this); // device context for painting
OnDraw(&dc);
Invalidate();
CView::OnRButtonUp(nFlags, point);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -