这个例子里面,我这个设置了鼠标单击移动的快慢 而且编译没有错误 为啥这个功能没反应 ?
请大神给我说一下、、、谢谢
// KeyTsetView.cpp : implementation of the CKeyTsetView class
//
#include "stdafx.h"
#include "KeyTset.h"
#include "KeyTsetDoc.h"
#include "KeyTsetView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CKeyTsetView
IMPLEMENT_DYNCREATE(CKeyTsetView, CView)
BEGIN_MESSAGE_MAP(CKeyTsetView, CView)
//{{AFX_MSG_MAP(CKeyTsetView)
ON_WM_KEYDOWN()
ON_WM_LBUTTONDOWN()
ON_WM_RBUTTONDOWN()
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CKeyTsetView construction/destruction
CKeyTsetView::CKeyTsetView()
{
// TODO: add construction code here
m_pt.x=200;
m_pt.y=200;
step=2;
i=0;
}
CKeyTsetView::~CKeyTsetView()
{
}
BOOL CKeyTsetView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CKeyTsetView drawing
void CKeyTsetView::OnDraw(CDC* pDC)
{
CKeyTsetDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
pDC->Ellipse(m_pt.x,m_pt.y,m_pt.x+50,m_pt.y+50); //画圆
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CKeyTsetView printing
BOOL CKeyTsetView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CKeyTsetView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CKeyTsetView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CKeyTsetView diagnostics
#ifdef _DEBUG
void CKeyTsetView::AssertValid() const
{
CView::AssertValid();
}
void CKeyTsetView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CKeyTsetDoc* CKeyTsetView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CKeyTsetDoc)));
return (CKeyTsetDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CKeyTsetView message handlers
void CKeyTsetView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
if(nChar==VK_LEFT)
{
m_pt.x=m_pt.x-step;
Invalidate();
}
if(nChar==VK_RIGHT)
{
m_pt.x=m_pt.x+step;
Invalidate();
}
if(nChar==VK_DOWN)
{
m_pt.y=m_pt.y+step;
Invalidate();
}
if(nChar==VK_UP)
{
m_pt.y=m_pt.y-step;
Invalidate();
}
CView::OnKeyDown(nChar, nRepCnt, nFlags);
}
void CKeyTsetView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
//radius=radius+5;
step=step+2;
Invalidate();
i++;
if(i==1)
{
m_pt11=m_pt12=point;
}
else{
CClientDC dc(this);
dc.MoveTo(m_pt11);
dc.LineTo(point);
m_pt11=point;
}
CView::OnLButtonDown(nFlags, point);
}
void CKeyTsetView::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CClientDC dc(this);
dc.MoveTo(m_pt11);
dc.LineTo(m_pt12);
i=0;
CView::OnRButtonDown(nFlags, point);
}
Invalidate();调用后,无论你在LButtonDown函数里画了什么,在函数退出后都会自动调用OnDraw清除背景然后画圆