Monday, November 9, 2009

Moving ball around screen

void CDrawCPRView::OnLButtonDblClk(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default

CClientDC *cr = new CClientDC(this);

CPen pn1;

pn1.CreatePen(PS_SOLID,2,RGB(255,0,0));

cr->SelectObject(pn1);

CBrush br1(RGB(255,0,0));

cr->SelectObject(br1);

//RedrawWindow();

while(1)
{

CRect rc;
GetClientRect(rc);
int x1=0,y1=0,a=0,b=0;

while(1)
{
if(a==0 && b==0)
{
x1+=5;
y1+=5;
}

if(a==0 && b==1)
{
x1+=5;
y1-=5;
}

if(a==1 && b==0)
{
x1-=5;
y1+=5;
}

if(a==1 && b==1)
{
x1-=5;
y1-=5;
}

if(x1 < a="0;" b="0;"> rc.right-2)
{
a=1;
}
else if(y1 > rc.bottom-2)
{
b=1;
}

RedrawWindow();
cr->Ellipse(x1,y1,x1+10,y1+10);
Sleep(20);
}

}

CView::OnLButtonDblClk(nFlags, point);
}

No comments:

Post a Comment