CPaintDC dc(this);
CRect rect;
this->GetClientRect(&rect);
//第一种方法
CDC pDC;
if(!pDC.CreateCompatibleDC(NULL)){
MessageBox("出错1");
return;
}
pDC.SelectObject(pBitmap[current]);
CMemDC mDC(&dc);
if(direction==RIGHT)
mDC.StretchBlt(0,0,rect.Width(),rect.Height(),&pDC,0,0,rect.Width(),rect.Height(),SRCCOPY);
else
mDC.StretchBlt(0,0,rect.Width(),rect.Height(),&pDC,rect.Width(),0,-rect.Width(),rect.Height(),SRCCOPY);
第二种方法
CDC pDC;
if(!pDC.CreateCompatibleDC(NULL)){
MessageBox("出错1");
return;
}
pDC.SelectObject(pBitmap[current]); CDC mDC;
if(!mDC.CreateCompatibleDC(NULL)){
MessageBox("出错2");
return;
}
CBitmap tempBitmap;
if(!tempBitmap.CreateCompatibleBitmap(&dc,rect.Width(),rect.Height()))
{
MessageBox("出错3");
return;
}
mDC.SelectObject(&tempBitmap);
mDC.FillSolidRect(0,0,rect.Width(),rect.Height(),RGB(255,255,255));
if(direction==RIGHT)
mDC.StretchBlt(0,0,rect.Width(),rect.Height(),&pDC,0,0,rect.Width(),rect.Height(),SRCCOPY);
else
mDC.StretchBlt(0,0,rect.Width(),rect.Height(),&pDC,rect.Width(),0,-rect.Width(),rect.Height(),SRCCOPY); dc.TransparentBlt(0,0,rect.Width(),rect.Height(),&mDC,0,0,rect.Width(),rect.Height(),RGB(255,255,255)); pDC.DeleteDC();
mDC.DeleteDC();小弟在实现动画的过程中使用上面两种双缓冲,可是画出的小人还是在闪,不知道为什么呵。请高手指点。用的是。NET
CMemDC是网上下的一个类代码如下
class CMemDC : public CDC
{
public: // 构造函数,设置内存DC
CMemDC(CDC* pDC) : CDC()
{
ASSERT(pDC != NULL); m_pDC = pDC;
m_pOldBitmap = NULL;
m_bMemDC = !pDC->IsPrinting();
if (m_bMemDC) // 创建内存DC
{
pDC->GetClipBox(&m_rect);
CreateCompatibleDC(pDC);
m_bitmap.CreateCompatibleBitmap(pDC, m_rect.Width(), m_rect.Height());
m_pOldBitmap = SelectObject(&m_bitmap);
SetWindowOrg(m_rect.left, m_rect.top);
}
else // 设置当前DC的备份,用于打印
{
m_bPrinting = pDC->m_bPrinting;
m_hDC = pDC->m_hDC;
m_hAttribDC = pDC->m_hAttribDC;
}
}
// 析构函数,备份内存DC的内容
~CMemDC()
{
if (m_bMemDC)
{
// 将位图拷贝到屏幕
m_pDC->TransparentBlt(m_rect.left, m_rect.top, m_rect.Width(), m_rect.Height(),
this, m_rect.left, m_rect.top,m_rect.Width(), m_rect.Height(), RGB(255,255,255)); SelectObject(m_pOldBitmap);
} else {
// All we need to do is replace the DC with an illegal value,
// this keeps us from accidently deleting the handles associated with
// the CDC that was passed to the constructor.
m_hDC = m_hAttribDC = NULL;
}
} // 允许作为指针使用
CMemDC* operator->() {return this;}
operator CMemDC*() {return this;}private:
CBitmap m_bitmap;
CBitmap* m_pOldBitmap;
CDC* m_pDC;
CRect m_rect;
BOOL m_bMemDC;
};
CRect rect;
this->GetClientRect(&rect);
//第一种方法
CDC pDC;
if(!pDC.CreateCompatibleDC(NULL)){
MessageBox("出错1");
return;
}
pDC.SelectObject(pBitmap[current]);
CMemDC mDC(&dc);
if(direction==RIGHT)
mDC.StretchBlt(0,0,rect.Width(),rect.Height(),&pDC,0,0,rect.Width(),rect.Height(),SRCCOPY);
else
mDC.StretchBlt(0,0,rect.Width(),rect.Height(),&pDC,rect.Width(),0,-rect.Width(),rect.Height(),SRCCOPY);
第二种方法
CDC pDC;
if(!pDC.CreateCompatibleDC(NULL)){
MessageBox("出错1");
return;
}
pDC.SelectObject(pBitmap[current]); CDC mDC;
if(!mDC.CreateCompatibleDC(NULL)){
MessageBox("出错2");
return;
}
CBitmap tempBitmap;
if(!tempBitmap.CreateCompatibleBitmap(&dc,rect.Width(),rect.Height()))
{
MessageBox("出错3");
return;
}
mDC.SelectObject(&tempBitmap);
mDC.FillSolidRect(0,0,rect.Width(),rect.Height(),RGB(255,255,255));
if(direction==RIGHT)
mDC.StretchBlt(0,0,rect.Width(),rect.Height(),&pDC,0,0,rect.Width(),rect.Height(),SRCCOPY);
else
mDC.StretchBlt(0,0,rect.Width(),rect.Height(),&pDC,rect.Width(),0,-rect.Width(),rect.Height(),SRCCOPY); dc.TransparentBlt(0,0,rect.Width(),rect.Height(),&mDC,0,0,rect.Width(),rect.Height(),RGB(255,255,255)); pDC.DeleteDC();
mDC.DeleteDC();小弟在实现动画的过程中使用上面两种双缓冲,可是画出的小人还是在闪,不知道为什么呵。请高手指点。用的是。NET
CMemDC是网上下的一个类代码如下
class CMemDC : public CDC
{
public: // 构造函数,设置内存DC
CMemDC(CDC* pDC) : CDC()
{
ASSERT(pDC != NULL); m_pDC = pDC;
m_pOldBitmap = NULL;
m_bMemDC = !pDC->IsPrinting();
if (m_bMemDC) // 创建内存DC
{
pDC->GetClipBox(&m_rect);
CreateCompatibleDC(pDC);
m_bitmap.CreateCompatibleBitmap(pDC, m_rect.Width(), m_rect.Height());
m_pOldBitmap = SelectObject(&m_bitmap);
SetWindowOrg(m_rect.left, m_rect.top);
}
else // 设置当前DC的备份,用于打印
{
m_bPrinting = pDC->m_bPrinting;
m_hDC = pDC->m_hDC;
m_hAttribDC = pDC->m_hAttribDC;
}
}
// 析构函数,备份内存DC的内容
~CMemDC()
{
if (m_bMemDC)
{
// 将位图拷贝到屏幕
m_pDC->TransparentBlt(m_rect.left, m_rect.top, m_rect.Width(), m_rect.Height(),
this, m_rect.left, m_rect.top,m_rect.Width(), m_rect.Height(), RGB(255,255,255)); SelectObject(m_pOldBitmap);
} else {
// All we need to do is replace the DC with an illegal value,
// this keeps us from accidently deleting the handles associated with
// the CDC that was passed to the constructor.
m_hDC = m_hAttribDC = NULL;
}
} // 允许作为指针使用
CMemDC* operator->() {return this;}
operator CMemDC*() {return this;}private:
CBitmap m_bitmap;
CBitmap* m_pOldBitmap;
CDC* m_pDC;
CRect m_rect;
BOOL m_bMemDC;
};
解决方案 »
- VC中使用webbrowser,我想拦截下载对话框,程序指定默认下载路径,取出文件名,做过的帮忙看看啊,分不多,50分敬上,勿怪,先谢谢大家了
- 为庆祝离开外包公司而散分。
- MFC中如何初始化EDIT的值
- 新手求助:客户端和服务器端如何通过响应指针进行通讯?
- CComboBox無法彈出list
- 遇到这样的类型转换该怎么办?
- 请问:用什么软件可将位图文件转换为矢量图形文件?并请告知下载地址!!!
- 【求助】VC对excel表格操作中,如何去删除一个表
- 怎样监控 TV BABY2开始运行?
- 为何别的机子运行不了我的ActiveX程序?
- 小心的问一下(vc程序员的薪水怎么样)?
- 请不要在留言里放那么多广告好不好,已经超过几屏了。!!!你们看得下去吗?
OnEraseBkgnd()返回TRUE后,再画图时,不需双缓冲,因为直接用BitBlt贴位图,就已经没有闪烁了。我的问题的出现在于,我已经用SetLayeredWindowAttributes将窗口的RGB(192,192,192)颜色弄没了,所以窗口是不可见的。我再用TransparentBlt画人,如果在OnEraseBkgnd()里面RETURN TRUE的话,窗口出现黑色背景,且小人会有残影。。如何去掉残影,实现透明背景呢。高手,你在哪