Write a Window Program to Move a Ball Horizontally inside the Client area using timer.At each time lapse the ball should should move left of the Window and when It Touches Left Boundary of the Window it Should go to,the right onf the window and so on.


LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;

HBRUSH br;
static int l,b,r,t,f;
HRGN hrgn;
RECT rect;
switch (message)
{
case WM_CREATE:
t=20;
b=20;
r=60;
l=60;
SetTimer(hWnd,1,100,NULL);
return 0;

case WM_TIMER:
GetClientRect(hWnd,&rect);
InvalidateRect(hWnd,&rect,true);
return 0;
case WM_PAINT:
hdc=BeginPaint(hWnd,&ps);
hdc=GetDC(hWnd);
GetClientRect(hWnd,&rect);
br=CreateSolidBrush(220);
if(b<rect.right-40 && f==0)
{
b=b+20;
r=r+20;
}
else
{
f=1;
b=b-20;
r=r-20;
if(b<rect.left)
f=0;
}
hrgn=CreateEllipticRgn(b,t,r,l);
FillRgn(hdc,hrgn,br);
EndPaint(hWnd,&ps);


return 0;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
   }
   return 0;
}

Comments

Popular posts from this blog

Uploading Image to Sql Server Image Datatype in asp.net using fileupload Control

Get Running Sum of Query SQL Query