www.pudn.com > MOUSEMove.rar > MOUSEMoveView.cpp


// MOUSEMoveView.cpp : implementation of the CMOUSEMoveView class 
// 
 
#include "stdafx.h" 
#include "MOUSEMove.h" 
 
#include "MOUSEMoveDoc.h" 
#include "MOUSEMoveView.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CMOUSEMoveView 
 
IMPLEMENT_DYNCREATE(CMOUSEMoveView, CView) 
 
BEGIN_MESSAGE_MAP(CMOUSEMoveView, CView) 
	//{{AFX_MSG_MAP(CMOUSEMoveView) 
	ON_WM_KEYDOWN() 
	ON_WM_MOUSEMOVE() 
	ON_WM_LBUTTONDOWN() 
	ON_WM_CHAR() 
	//}}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() 
 
///////////////////////////////////////////////////////////////////////////// 
// CMOUSEMoveView construction/destruction 
 
CMOUSEMoveView::CMOUSEMoveView() 
{ 
	pos.x=20; 
    pos.y=20; 
    radius=10; 
 
	number = 0; 
} 
 
CMOUSEMoveView::~CMOUSEMoveView() 
{ 
} 
 
BOOL CMOUSEMoveView::PreCreateWindow(CREATESTRUCT& cs) 
{ 
	// TODO: Modify the Window class or styles here by modifying 
	//  the CREATESTRUCT cs 
 
	return CView::PreCreateWindow(cs); 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CMOUSEMoveView drawing 
 
void CMOUSEMoveView::OnDraw(CDC* pDC) 
{ 
	CMOUSEMoveDoc* pDoc = GetDocument(); 
	ASSERT_VALID(pDoc); 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CMOUSEMoveView printing 
 
BOOL CMOUSEMoveView::OnPreparePrinting(CPrintInfo* pInfo) 
{ 
	// default preparation 
	return DoPreparePrinting(pInfo); 
} 
 
void CMOUSEMoveView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) 
{ 
	// TODO: add extra initialization before printing 
} 
 
void CMOUSEMoveView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) 
{ 
	// TODO: add cleanup after printing 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CMOUSEMoveView diagnostics 
 
#ifdef _DEBUG 
void CMOUSEMoveView::AssertValid() const 
{ 
	CView::AssertValid(); 
} 
 
void CMOUSEMoveView::Dump(CDumpContext& dc) const 
{ 
	CView::Dump(dc); 
} 
 
CMOUSEMoveDoc* CMOUSEMoveView::GetDocument() // non-debug version is inline 
{ 
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMOUSEMoveDoc))); 
	return (CMOUSEMoveDoc*)m_pDocument; 
} 
#endif //_DEBUG 
 
///////////////////////////////////////////////////////////////////////////// 
// CMOUSEMoveView message handlers 
 
void CMOUSEMoveView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)  
{ 
	CClientDC dc(this); 
	char str[30]; 
	sprintf(str,"Virtual Key Code=0x%0x",nChar); 
	dc.SetTextColor(RGB(255,0,0)); 
	dc.TextOut(300,0,str,strlen(str)); 
	CView::OnKeyDown(nChar, nRepCnt, nFlags); 
} 
 
void CMOUSEMoveView::OnMouseMove(UINT nFlags, CPoint point)  
{ 
	 
	CClientDC dc(this); 
	char str[30]; 
	sprintf(str,"[%03d,%03d]",point.x,point.y); 
	dc.SetTextColor(RGB(0,255,0)); 
	dc.SetBkColor(RGB(255,0,0)); 
	dc.TextOut(0,0,str); 
	CView::OnMouseMove(nFlags, point); 
} 
 
void CMOUSEMoveView::OnLButtonDown(UINT nFlags, CPoint point)  
{ 
	CClientDC dc(this); 
	char str[30]; 
	sprintf(str,"[%03d,%03d]",point.x,point.y); 
	 
	m_num[number++] = point; 
	dc.SetTextColor(RGB(0,255,0)); 
	//dc.TextOut(point.x,point.y,str); 
	dc.SetPixel(point.x,point.y,RGB(255,0,0)); 
	//if(number>1) 
	{ 
		dc.MoveTo(m_num[number-1].x,m_num[number-1].y); 
	 
		dc.LineTo(m_num[number].x,m_num[number].y); 
	} 
	CView::OnLButtonDown(nFlags, point); 
} 
 
void CMOUSEMoveView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)  
{ 
	CClientDC dc(this); 
	char str[30]; 
	sprintf(str,"Char Code=%d",nChar); 
	dc.TextOut(300,100,str,strlen(str)); 
 
	if(nChar>='0'&&nChar<='9') 
		MessageBox("ÄãÊäÈëÁËÊý×Ö"); 
	CView::OnChar(nChar, nRepCnt, nFlags); 
}