我用App Wizard 创建了一个单文档的应用程序,想在view区显示鼠标的位置。核心的原程序如下:
void CCaptureMouseView::OnMouseMove(UINT nFlags, CPoint point)
{
//SetCapture()和ReleaseCapture函数在void CCaptureMouseView::OnLButtonDown(UINT nFlags, CPoint point) 和OnLButtonDown(UINT nFlags, CPoint point)中书写。
// TODO: Add your message handler code here and/or call default
CDC *pDC = GetDC();
char buf[100];
wsprintf( buf, "鼠标坐标:%d,%d", point.x, point.y);
pDC->TextOut ( 0,10,"鼠标捕获实例");
pDC->TextOut ( 0,30, buf);
CView::OnMouseMove(nFlags, point);
}
现在出现的问题是:若当前鼠标的位置是(20,349),当鼠标移到(2,3)时,由于没有及时刷新,显示的鼠标坐标变成了(2,3349),所以我的问题是当第2次显示鼠标位置时如何将上一个位置的坐标清除掉。请指教。
void CCaptureMouseView::OnMouseMove(UINT nFlags, CPoint point)
{
//SetCapture()和ReleaseCapture函数在void CCaptureMouseView::OnLButtonDown(UINT nFlags, CPoint point) 和OnLButtonDown(UINT nFlags, CPoint point)中书写。
// TODO: Add your message handler code here and/or call default
CDC *pDC = GetDC();
char buf[100];
wsprintf( buf, "鼠标坐标:%d,%d", point.x, point.y);
pDC->TextOut ( 0,10,"鼠标捕获实例");
pDC->TextOut ( 0,30, buf);
CView::OnMouseMove(nFlags, point);
}
现在出现的问题是:若当前鼠标的位置是(20,349),当鼠标移到(2,3)时,由于没有及时刷新,显示的鼠标坐标变成了(2,3349),所以我的问题是当第2次显示鼠标位置时如何将上一个位置的坐标清除掉。请指教。
{
//SetCapture()和ReleaseCapture函数在void CCaptureMouseView::OnLButtonDown(UINT nFlags, CPoint point) 和OnLButtonDown(UINT nFlags, CPoint point)中书写。
// TODO: Add your message handler code here and/or call default
CDC *pDC = GetDC();
char buf[100];
wsprintf( buf, "鼠标坐标:%d,%d", point.x, point.y);
pDC->TextOut ( 0,10,"鼠标捕获实例");
pDC->TextOut ( 0,30, " ");
pDC->TextOut ( 0,30, buf);
CView::OnMouseMove(nFlags, point);
}写一个长的空格串好了
例如:pDC->TextOut ( 0,30, " ");
pDC->TextOut ( 0,30, buf);
这样就可以实现楼主的要求了,祝你成功!
而在CCaptureMouseView::OnMouseMove里可以调用OnInvalidate。
在CCaptureMouseView做一个全局变量存础当前MOUSE当前位置。在OnDrawJ里显示。