用Timer和Bitblt实现背景滚动的问题
staticinti=0;CClientDCdc1(this);CClientDCdc2(this);CDC*mdc1=newCDC;CDC*mdc2=newCDC;ba...
static int i=0;
CClientDC dc1(this);
CClientDC dc2(this);
CDC *mdc1=new CDC;
CDC *mdc2=new CDC;
backBitmap1->m_hObject=LoadImage(NULL,"Background1.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
backBitmap2->m_hObject=LoadImage(NULL,"Background1.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
mdc1->CreateCompatibleDC(&dc1);
mdc1->SelectObject(backBitmap1);
mdc2->CreateCompatibleDC(&dc2);
mdc2->SelectObject(backBitmap2);
if(0+10*i>=512)
{
dc1.BitBlt(0,-512,512,512,mdc1,0,0,SRCCOPY);
dc2.BitBlt(0,0,512,512,mdc2,0,0,SRCCOPY);
i=0;
return;
}
dc1.BitBlt(0,-512+10*i,512,512,mdc1,0,0,SRCCOPY);
dc2.BitBlt(0,0+10*i,512,512,mdc2,0,0,SRCCOPY);
i++;
CView::OnTimer(nIDEvent);
这段代码意在实现背景滚动。。。可是为什么滚动只实现了一次后 就停止了贴图呢,
而OnTimer函数一直在运行
运行一段时间就自动停止贴图了。。。 展开
CClientDC dc1(this);
CClientDC dc2(this);
CDC *mdc1=new CDC;
CDC *mdc2=new CDC;
backBitmap1->m_hObject=LoadImage(NULL,"Background1.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
backBitmap2->m_hObject=LoadImage(NULL,"Background1.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
mdc1->CreateCompatibleDC(&dc1);
mdc1->SelectObject(backBitmap1);
mdc2->CreateCompatibleDC(&dc2);
mdc2->SelectObject(backBitmap2);
if(0+10*i>=512)
{
dc1.BitBlt(0,-512,512,512,mdc1,0,0,SRCCOPY);
dc2.BitBlt(0,0,512,512,mdc2,0,0,SRCCOPY);
i=0;
return;
}
dc1.BitBlt(0,-512+10*i,512,512,mdc1,0,0,SRCCOPY);
dc2.BitBlt(0,0+10*i,512,512,mdc2,0,0,SRCCOPY);
i++;
CView::OnTimer(nIDEvent);
这段代码意在实现背景滚动。。。可是为什么滚动只实现了一次后 就停止了贴图呢,
而OnTimer函数一直在运行
运行一段时间就自动停止贴图了。。。 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询