?? mousedemoview.cpp
字號:
// MouseDemoView.cpp : CMouseDemoView 類的實現
//
#include "stdafx.h"
#include "MouseDemo.h"
#include "MouseDemoDoc.h"
#include "MouseDemoView.h"
#include ".\mousedemoview.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CMouseDemoView
IMPLEMENT_DYNCREATE(CMouseDemoView, CView)
BEGIN_MESSAGE_MAP(CMouseDemoView, CView)
// 標準打印命令
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
END_MESSAGE_MAP()
// CMouseDemoView 構造/析構
CMouseDemoView::CMouseDemoView()
: m_IsDown(false)
, m_MyText(_T(""))
{
// TODO: 在此處添加構造代碼
}
CMouseDemoView::~CMouseDemoView()
{
}
BOOL CMouseDemoView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: 在此處通過修改 CREATESTRUCT cs 來修改窗口類或
// 樣式
return CView::PreCreateWindow(cs);
}
// CMouseDemoView 繪制
void CMouseDemoView::OnDraw(CDC* /*pDC*/)
{
CMouseDemoDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
// TODO: 在此處為本機數據添加繪制代碼
}
// CMouseDemoView 打印
BOOL CMouseDemoView::OnPreparePrinting(CPrintInfo* pInfo)
{
// 默認準備
return DoPreparePrinting(pInfo);
}
void CMouseDemoView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: 打印前添加額外的初始化
}
void CMouseDemoView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: 打印后添加清除過程
}
// CMouseDemoView 診斷
#ifdef _DEBUG
void CMouseDemoView::AssertValid() const
{
CView::AssertValid();
}
void CMouseDemoView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CMouseDemoDoc* CMouseDemoView::GetDocument() const // 非調試版本是內聯的
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMouseDemoDoc)));
return (CMouseDemoDoc*)m_pDocument;
}
#endif //_DEBUG
// CMouseDemoView 消息處理程序
void CMouseDemoView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息處理程序代碼和/或調用默認值
SetCapture();//捕獲鼠標
RECT rect;
GetClientRect(&rect);
ClientToScreen(&rect);
ClipCursor(&rect);
this->m_IsDown=true;
this->m_MyText.Format("您單擊的位置為:X=%d,Y=%d" ,point.x,point.y);
CDC* pDC;
pDC=GetDC();
pDC->TextOut(10,10,m_MyText,m_MyText.GetLength());
CView::OnLButtonDown(nFlags, point);
}
void CMouseDemoView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息處理程序代碼和/或調用默認值
ReleaseCapture();//釋放鼠標
ClipCursor(NULL);
this->m_IsDown=false;
this->m_MyText.Format("您單擊的位置為:X=%d,Y=%d" ,point.x,point.y);
CDC* pDC;
pDC = GetDC();
pDC->TextOut(10,10,m_MyText,m_MyText.GetLength());
CView::OnLButtonUp(nFlags, point);
}
void CMouseDemoView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息處理程序代碼和/或調用默認值
if(m_IsDown)
{
this->m_MyText.Format("您單擊的位置為:X=%d,Y=%d" ,point.x,point.y);
CDC* pDC;
pDC=GetDC();
pDC->TextOut(10,10,m_MyText,m_MyText.GetLength());
}
CView::OnMouseMove(nFlags, point);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -