Monday, April 19, 2010

Button

Button
6.Window Procedure:
a)WM_PAINT:
i)Get the device context handle and coordinates of client area.
ii)Draw the text at the center of client area.
b)WM_COMMAND:
i)When the child window control is pressed,corresponding message is
sent to window procedure.
c)WM_LBUTTONDOWN:
Set the flag value to ‘1’
d)WM_MOUSEMOVE:
1.if the flag is set to ‘1’,get the device context handle
2.set the pixel value
e)WM_LBUTTONUP:
set the flag value to ‘0’
f)WM_DESTROY:
i)Post quit message that generates WM_DESTROY
g)Default:
Other messages are handled by default window procedure.
long _stdcall wproc(HWND hwnd,UINT x,WPARAM w,LPARAM lp)
{
HDC hdc;
HWND h1,h2,h3;
static RECT rect;
switch(x)
{
case WM_CREATE:

h1=CreateWindow("button","rect",WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,20,80,60,60,hwnd,(HMENU)1,hinst,0);
h2=CreateWindow("button","ellipse",WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,20,10,60,60,hwnd,(HMENU)2,hinst,0);
h3=CreateWindow("button","poly",WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,20,200,60,60,hwnd,(HMENU)3,hinst,0);
return 0;
case WM_COMMAND:
if(LOWORD(w)==1 && HIWORD(w)==0)
f=1;
else if(LOWORD(w)==2 && HIWORD(w)==0)
f=2;
else if(LOWORD(w)==3 && HIWORD(w)==0)
f=3;
break;
case WM_LBUTTONDOWN:

x1=LOWORD(lp);
y1=HIWORD(lp);
hdc=GetDC(hwnd);
InvalidateRect(hwnd,&rect,TRUE);
GetUpdateRect(hwnd,&rect,TRUE);
ValidateRect(hwnd,&rect);
if(f==3)
{

c[i].x=x1;
c[i].y=y1;
i++;
SetPixel(hdc,x1,y1,RGB(255,0,0));
}
if(i==6)
{
Polygon(hdc,c,6);
i=0;
}
flag=1;
ReleaseDC(hwnd,hdc);
break;
case WM_MOUSEMOVE:
if(flag==1)
{
x2=LOWORD(lp);
y2=HIWORD(lp);
hdc=GetDC(hwnd);
InvalidateRect(hwnd,&rect,TRUE);
GetUpdateRect(hwnd,&rect,TRUE);
ValidateRect(hwnd,&rect);
rect.left=x1;
rect.bottom=y2;
rect.top=y1;
rect.right=x2;
if(f==1)
Rectangle(hdc,x1,y1,x2,y2);
else if(f==2)

Ellipse(hdc,x1,y1,x2,y2);
ReleaseDC(hwnd,hdc);
}
break;
case WM_LBUTTONUP:
flag=0;
SetRect(&rect,0,0,0,0);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;

default:
return DefWindowProc(hwnd,x,w,lp);

}
}

No comments:

Post a Comment