6/11/10

/* Line joining 2 points*/

Buzz It
#include
long _stdcall me(HWND,UINT,UINT,long);
WNDCLASS a;
int _stdcall WinMain(HINSTANCE i,HINSTANCE j,char * k,int l)
{
HWND h;
MSG m;
a.hbrBackground =(HBRUSH)GetStockObject(WHITE_BRUSH);
a.hCursor =LoadCursor (0,IDC_ARROW);
a.hInstance =i;
a.lpfnWndProc =me;
a.lpszClassName ="center";
h=CreateWindow ("center","press",WS_OVERLAPPEDWINDOW,20,30,400,500,0,0,i,0);
ShowWindow (h,l);
while(GetMessage (&m,0,0,0))
{
DispatchMessage (&m);
}
return 0;
}
long _stdcall me(HWND w,UINT x,UINT y,long z)
{
HDC d;
PAINTSTRUCT p;
static POINT pt[2];
static int cnt=0;
switch(x)
{
case WM_LBUTTONDOWN:
pt[cnt].x=LOWORD(z);
pt[cnt].y =HIWORD(z);
cnt++;
d=GetDC(w);
InvalidateRect (w,NULL,TRUE);
return 0;
case WM_PAINT:
d=BeginPaint (w,&p);
if(cnt==2)
{
MoveToEx (d,pt[1].x,pt[1].y,NULL);
LineTo(d,pt[0].x,pt[0].y);
pt[0].x=0;
pt[1].x=0;
pt[0].y=0;
pt[1].y=0;
cnt=0;
}
pt[cnt].x=pt[cnt+1].x;
pt[cnt].y=pt[cnt+1].y;
return 0;
case WM_LBUTTONUP:
InvalidateRect (w,NULL,TRUE);
return 0;
case WM_DESTROY:
PostQuitMessage (0);
return 0;
default:
return(DefWindowProc (w,x,y,z));

}
return 0;
}

O/P



0 comments:

Post a Comment