如何在OnMouseMove中画线?
如何在OnMouseMove中给鼠标加上移动线?
就是一条黑线可以左右移动
void CMyView::OnMouseMove(UINT nFlags, CPoint point)
{
CDC* pDC=GetDC();
struct {
int XLeft;
int XRight;
int YTOP;
int YBottom;
}SCurveRect;
gXLeft=1500;
SCurveRect.XLeft=gXLeft;
SCurveRect.XRight=20100;
SCurveRect.YTOP=4000;
SCurveRect.YBottom=-4000;
int iBottomSpace=80;//底部空白
//设置坐标
pDC-> SetMapMode(MM_ANISOTROPIC);
CRect rectClient,rectClient2;
GetClientRect(rectClient);
pDC-> SetMapMode(MM_ANISOTROPIC);
pDC-> SetWindowExt(CSize(20400,11720));
pDC-> SetViewportExt(rectClient.right,-rectClient.bottom);
pDC-> SetViewportOrg(rectClient.left,rectClient.bottom/2-iBottomSpace); //设置窗口左下角为原点坐标
if (point.x*20> SCurveRect.XRight)
point.x=SCurveRect.XRight/20;
if (point.x*20 <SCurveRect.XLeft)
point.x=SCurveRect.XLeft/20;
pDC-> MoveTo(point.x*20,SCurveRect.YTOP);
pDC-> LineTo(point.x*20,SCurveRect.YBottom);
CView::OnMouseMove(nFlags, point);
}
但是这样上次画的线都没有被清除,过一会就全黑了。
如果用InvalidateRect()就非常Flash了。。。
[解决办法]
用xor画,每次把上次的擦掉。