代码如下:
Cxx::jj(int x,int y)
{
CBrush *brushred;
CRect t00,t01,t02,t03;
// rect=new CRect(250,50,250+20*x,50+20*y);
t00=new CRect(250+20*x,50+20*y,250+20*(x+1),50+20*(y+1));
t01=new CRect(250+20*(x+1),50+20*y,250+20*(x+2),50+20*(y+1));
t02=new CRect(250+20*(x+2),50+20*y,250+20*(x+3),50+20*(y+1));
t03=new CRect(250+20*(x+1),50+20*(y+1),250+20*(x+2),50+20*(y+2)); brushred=new CBrush(RGB(255,0,0));
GetDC()->SelectObject(brushred);
GetDC()->FillRect(&t00,brushred);
GetDC()->FillRect(&t01,brushred);
GetDC()->FillRect(&t02,brushred);
GetDC()->FillRect(&t03,brushred);
delete brushred;
}void CA8View::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
b++;
//CRect r1(250+20*a,50+20*b,250+20*(a+1),50+20*(b+1));
this->jj(a,b); CView::OnTimer(nIDEvent);
}主要的代码以在这里了。
运行之后,为什么那块东西下来时上面的部分不会消失呢?一定要通过改变窗口的大小激发刷新才能使上面的部分消失呢?清高手指点。先谢了。
Cxx::jj(int x,int y)
{
CBrush *brushred;
CRect t00,t01,t02,t03;
// rect=new CRect(250,50,250+20*x,50+20*y);
t00=new CRect(250+20*x,50+20*y,250+20*(x+1),50+20*(y+1));
t01=new CRect(250+20*(x+1),50+20*y,250+20*(x+2),50+20*(y+1));
t02=new CRect(250+20*(x+2),50+20*y,250+20*(x+3),50+20*(y+1));
t03=new CRect(250+20*(x+1),50+20*(y+1),250+20*(x+2),50+20*(y+2)); brushred=new CBrush(RGB(255,0,0));
GetDC()->SelectObject(brushred);
GetDC()->FillRect(&t00,brushred);
GetDC()->FillRect(&t01,brushred);
GetDC()->FillRect(&t02,brushred);
GetDC()->FillRect(&t03,brushred);
delete brushred;
}void CA8View::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
b++;
//CRect r1(250+20*a,50+20*b,250+20*(a+1),50+20*(b+1));
this->jj(a,b); CView::OnTimer(nIDEvent);
}主要的代码以在这里了。
运行之后,为什么那块东西下来时上面的部分不会消失呢?一定要通过改变窗口的大小激发刷新才能使上面的部分消失呢?清高手指点。先谢了。
好象是OnPaint我也记不得了,看看你View类的成员函数
不过那样的话估计屏幕要闪烁
还要使用别的方法来处理
{
b++;
Invalidate(); CView::OnTimer(nIDEvent);
}void CA8View::OnDraw()
{
jj(a, b);
}可以照我说的修改,不过即使这样修改,效果还是很差的,肯定闪烁,更好的画法是将你画的操作先在内存DC上作好,然后一次贴到当前View的dc上去,这样就不会闪烁
使用失效函数吧”
是指 Invalidate(FALSE)吧?
能否在详细点?麻烦你再详细一点行吗?谢谢你。
然后再画,就可一不用老是调用INVALIDATE()了(不然屏幕可能闪烁的较厉害),
void CA8View::OnTimer(UINT nIDEvent)
{
Invalidate(FALSE);
CView::OnTimer(nIDEvent);
}
void CA8View::OnDraw(CDC* pDC)
{
this->jj(a,b,pDC)
}
注意a,b设置为类成员函数,如果需要修改的话就放在OnTimer函数中。
另处修改你的jj函数为以下形式:
Cxx::jj(int x,int y,CDC* pDC)
{
CBrush *brushred;
CRect t00,t01,t02,t03;
// rect=new CRect(250,50,250+20*x,50+20*y);
t00=new CRect(250+20*x,50+20*y,250+20*(x+1),50+20*(y+1));
t01=new CRect(250+20*(x+1),50+20*y,250+20*(x+2),50+20*(y+1));
t02=new CRect(250+20*(x+2),50+20*y,250+20*(x+3),50+20*(y+1));
t03=new CRect(250+20*(x+1),50+20*(y+1),250+20*(x+2),50+20*(y+2)); brushred=new CBrush(RGB(255,0,0));
pDC()SelectObject(brushred);
pDC->FillRect(&t00,brushred);
pDC->FillRect(&t01,brushred);
pDC->FillRect(&t02,brushred);
pDC->FillRect(&t03,brushred);
delete brushred;
}