求助?

tracymaidi 2009-10-12 12:06:18
编写一个冒泡程序。单击左键在单击处生成一个蓝色的泡泡,单击右键在单击处生成一个黄色的泡泡。这些泡泡的半径是随机的,以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个像素单位向上移动呢?请好心人帮我仔细看看,能不能给出一个详细的解决办法我?谢谢了!
...全文
50 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

16,551

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧