case WM_LBUTTONDOWN:
xPos=LOWORD(lParam);
yPos=HIWORD(lParam); break; case WM_MOUSEMOVE:
ptMouse.x=LOWORD(lParam);
ptMouse.y=HIWORD(lParam); MoveToEx(GetDC(hWnd),xPos,yPos,NULL);
LineTo(GetDC(hWnd),ptMouse.x,ptMouse.y);
wsprintf(szTitle,"Mouse Position: X=%d ,Y=%d ",ptMouse.x,ptMouse.y);
TextOut(GetDC(hWnd),500,200,szTitle,strlen(szTitle));
InvalidateRect(hWnd,NULL,FALSE);
xPos=ptMouse.x;
xPos=ptMouse.y; break;
xPos=LOWORD(lParam);
yPos=HIWORD(lParam); break; case WM_MOUSEMOVE:
ptMouse.x=LOWORD(lParam);
ptMouse.y=HIWORD(lParam); MoveToEx(GetDC(hWnd),xPos,yPos,NULL);
LineTo(GetDC(hWnd),ptMouse.x,ptMouse.y);
wsprintf(szTitle,"Mouse Position: X=%d ,Y=%d ",ptMouse.x,ptMouse.y);
TextOut(GetDC(hWnd),500,200,szTitle,strlen(szTitle));
InvalidateRect(hWnd,NULL,FALSE);
xPos=ptMouse.x;
xPos=ptMouse.y; break;
yPos=HIWORD(lParam);WM_LBUTTONDOWN 消息结束后 xpos = ypos = 0;
正确的写法 static xpos,ypos;
ptMouse.x=LOWORD(lParam);
ptMouse.y=HIWORD(lParam);if(xPos!=0 ||yPos!=0)
{
MoveToEx(GetDC(hWnd),xPos,yPos,NULL);
LineTo(GetDC(hWnd),ptMouse.x,ptMouse.y);
...
}
);
xPos=ptMouse.x;
xPos=ptMouse.y;
不可以
xPos=ptMouse.x;
xPos=ptMouse.y;//应该是yPos=ptMouse.y;吧
case WM_LBUTTONDOWN:
xPos=ptMouse.x=LOWORD(lParam);
yPos=ptMouse.y=HIWORD(lParam);
LineTo(GetDC(hWnd),ptMouse.x,ptMouse.y); HDC pDC = GetDC(hWbd);
MoveToEx(pDC,xPos,yPos,NULL);
LineTo(pDC,ptMouse.x,ptMouse.y);
绝对OK