-
Help!!!
I am quite new with Visual C++. I know C++ pretty good. I am starting to write small programs in VC++ , at the moment Win32 application to draw lines with mouse movements.
Ok..now the problem..
I wrote a small program that draws lines on mousedown and mouseup. ie. It captures the mouse co-ordinates in WM_LBUTTONDOWN , saves it to two variables, and in WM_LBUTTONDOWN captures the mouse co-ordinates and draw a line btn these two points. But it always draw the line from top left of the window to the current point. Can u please help me ? Here is my code.
case WM_LBUTTONDOWN:
POINTS p;
p=MAKEPOINTS(lParam);
xPos=p.x;
yPos=p.y;
break;
case WM_LBUTTONUP:
p=MAKEPOINTS(lParam);
MoveToEx(GetDC(hWnd),p.x,p.y,NULL);
LineTo(GetDC(hWnd),p.x+10,p.y+10);
break;
xPos and yPos I declared as global variables. where is my mistake?
-
Sorrry!!!!!! This is the actual code...
case WM_LBUTTONDOWN:
POINTS p;
p=MAKEPOINTS(lParam);
xPos=p.x;
yPos=p.y;
break;
case WM_LBUTTONUP:
p=MAKEPOINTS(lParam);
MoveToEx(GetDC(hWnd),p.x,p.y,NULL);
LineTo(GetDC(hWnd),xPos,yPos);
break;
-
why MoveToEx?
i suggest using MFC for this as it's way easier. if you want to
do this MFC let me know
-
i know it's possible with MFC..but i want to do it from the base level...it should be possible here also ...so...how?
-
POINTS p; is defined locally. You use this variable in MoveToEx(GetDC(hWnd),p.x,p.y,NULL);. The variable p must be either static or global for it to retain its value. In other words, you are moving to a value that is not set and therefore is the upper left of the window (0,0).