07基本鼠标操作——判断鼠标消息

WM_LBUTTONDOWN:左键按下

WM_LBUTTONUP:左键弹起

WM_MOUSEMOVE:移动

void CBaseMouseDemoView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	bDrag=TRUE;
	ptUp=ptDown=point;//记录鼠标当前位置
	CView::OnLButtonDown(nFlags, point);
}

void CBaseMouseDemoView::OnLButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	if(bDrag)
	{
		ptUp=point;
		DrawCircle();									//画新圆
		bDrag=FALSE;
	}
	
	CView::OnLButtonUp(nFlags, point);
}

void CBaseMouseDemoView::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	if(bDrag)
	{
		ptUp=point;//记录鼠标的当前位置
		DrawCircle();									//画新圆
	}
	CView::OnMouseMove(nFlags, point);
}

void CBaseMouseDemoView::DrawCircle()
{
	Invalidate(false);
	CClientDC dc(this);							//获取DC
	CRect rect;
	GetClientRect(rect);							//获取客户窗口区域
	CBrush brush(RGB(255,255,255));
	dc.FillRect(rect,&brush);						//填充背景色为白色
	dc.Ellipse(ptDown.x,ptDown.y,ptUp.x,ptUp.y);		//绘制矩形

}



你可能感兴趣的:(07基本鼠标操作——判断鼠标消息)