求助?
编写一个冒泡程序。单击左键在单击处生成一个蓝色的泡泡,单击右键在单击处生成一个黄色的泡泡。这些泡泡的半径是随机的,以100ms的时间间隔、10个像素的间隔向上冒。
public:
int flag,i;
CRect r1;
BOOL CMy5Doc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
// TODO: add reinitialization code here
// (SDI documents will reuse this document)
i=0;
return TRUE;
}
void CMy5View::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CMy5Doc*pDoc=GetDocument();
pDoc->flag=0;
SetTimer(1,100,NULL);
int r=rand()%50+10;
CRect rect(point.x-r,point.y-r,point.x+r,point.y+r);
pDoc->r1=rect;
Invalidate(FALSE);
CView::OnLButtonDown(nFlags, point);
}
void CMy5View::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CMy5Doc*pDoc=GetDocument();
pDoc->flag=1;
int r=rand()%50+10;
CRect rect(point.x-r,point.y-r,point.x+r,point.y+r);
pDoc->r1=rect;
Invalidate(FALSE);
CView::OnRButtonDown(nFlags, point);
}
void CMy5View::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CMy5Doc*pDoc=GetDocument();
pDoc->i+=1;
Invalidate(FALSE);
CView::OnTimer(nIDEvent);
}
void CMy5View::OnDraw(CDC* pDC)
{
CMy5Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CBrush brush,newbrush,*oldbrush;
brush.CreateSolidBrush(RGB(0,0,255));
newbrush.CreateSolidBrush(RGB(255,255,0));
if(pDoc->flag==0)
{
oldbrush=pDC->SelectObject(&brush);
pDC->Ellipse(pDoc->r1);
CSize offset(10);
pDoc->r1+=offset;
Invalidate(TRUE);
pDC->Ellipse(pDoc->r1);
}
else
{
oldbrush=pDC->SelectObject(&newbrush);
pDC->Ellipse(pDoc->r1);
}
pDC->SelectObject(oldbrush);
// TODO: add draw code for native data here
}
请教一下,在函数 void CMy5View::OnTimer(UINT nIDEvent) 里面怎么把这个pDoc->i+=10利用到,pDC->Ellipse(pDoc->r1)跟pDoc->i+=10怎么结合起来实现圆的10个像素单位向上移动呢?请好心人帮我仔细看看,能不能给出一个详细的解决办法我?谢谢了!