Monday, April 19, 2010

Free hand I and II

FREE HAND DRAWING-1&II
6.Window Procedure(I&II)
a) WM_LBUTTONDOWN:
i)Set a flag value
b) WM_MOUSEMOVE:
i)Set the pixel if flag is true
ii)Print the pixel
c) WM_LBUTTONUP:
i)Reset the flag value
d)WM_DESTROY
Post quit Message that generates WM_QUIT
e) Default:
Other messages are handled by the default window procedure.
I
Int flag=0;
long _stdcall WProc (HWND hwnd,UINT x,WPARAM w,LPARAM l)
{
switch(x)
{
case WM_LBUTTONDOWN:
flag=1;break;
case WM_MOUSEMOVE:
if(flag==1)
{
hdc=GetDC(hwnd);
SetPixel(hdc,LOWRD(l),HIWORD(l),RGB(255,255.255));
ReleaseDC(hwnd,hdc);
}
Break;
case WM_LBUTTONUP:
flag=0;
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,x,w,l);
}
return 0;}
II
Int flag=0;
Int x1,y1,x2,y2;
long _stdcall WProc (HWND hwnd,UINT x,WPARAM w,LPARAM l)
{
switch(x)
{
case WM_LBUTTONDOWN:
if(flag==0)
{
x1=LOWORD(l);
y1=HIWORD(l);
flag=1;
}
break;
case WM_MOUSEMOVE:
if(flag==1)
{
x2=LOWORD(l);
y2=HIWORD(l);
hdc = GetDC(hwnd);
MOVETOEX(hdc,x1,y1,0);
LineTo(hdc,x2,y2);
ReleaseDC(hwnd,hdc);
x1=x2;
y1=y2;
}
break;
case WM_LBUTTONUP:
flag=0;
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,x,w,l);
}return 0;}

KEYBOARD EVENTS-PROCESSING CHARACTER MESSAGES
6.window procedure
a)WM_CHAR: -It is used to handle character keys.
b)InvalidateRect is used for making variable invalid.
c)GetUpdateRect is used for returning co-ordinate value of client area and validate client area.
d)GetKeyNameText is used to get keys name.
e)WM_DESTROY:
Post Quit Message that generates WM_QUIT.
f)default:
Other messages are handled by the default window procedure.
long _stdcall wproc(HWND hwnd,UINT x,WPARAM w,LPARAM l)
{
HDC hdc;char buffer[100];
TCHAR szkeyname[30];
switch(x)
{
case WM_CHAR:
hdc=GetDC(hwnd);
InvalidateRect(hwnd,NULL,TRUE);
GetUpdateRect(hwnd,NULL,TRUE);
ValidateRect(hwnd,NULL);
GetKeyNameText(1,szkeyname,sizeof(szkeyname)/sizeof(TCHAR));
wsprintf(buffer,"keypressed=%c",w);
TextOut(hdc,0,20,buffer,strlen(buffer));
TextOut(hdc,120,0,szkeyname,strlen(szkeyname));
wsprintf(buffer,"keypressed=%d",w);
TextOut(hdc,0,50,buffer,strlen(buffer));
break;
case WM_DESTROY:
PostQuitMessage(0);break;
default:return DefWindowProc(hwnd,x,w,l);
}return 0;}

No comments:

Post a Comment