Write a VC++ Program to draw Lines from Fixed Point to Current Mouse Position as Mouse Moved Around the Point.Each time you press the mouse drawing should begin from the Point you Click. (FreeHand Drawing)
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
static int x,y,i;
static int x1,y1,f=0;
switch (message)
{
case WM_LBUTTONDOWN:
if(f==0)
{
hdc=GetDC(hWnd);
x=LOWORD(lParam);
y=HIWORD(lParam);
f=1;
}
break;
case WM_MOUSEMOVE:
if(f==1)
{
hdc=GetDC(hWnd);
x1=LOWORD(lParam);
y1=HIWORD(lParam);
}
MoveToEx(hdc,x,y,0);
LineTo(hdc,x1,y1);
x=x1;
y=y1;
break;
case WM_LBUTTONUP:
f=0;
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
Comments
Post a Comment