GDI+ 画窗体背景 闪烁。 gdi+双缓冲 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 窗口创建的时候会重绘一次,这时候也画一次背景。具体的消息忘记了,用spy++抓下看看。另外,窗口创建完毕后调用UpdateWindow可能有效果。Windows GDI坑比较多,在不同系统上表现也不一致,还是多试试看吧。 没有看到内存兼容DC,CDCHandle是什么?双缓冲绘图,HDC hMemDC, hBITMAP hMemBitmap; 我这个是 WTL, 用的GDI + ...CDCHandle 是WTL 里面的CDC 的一个类 感觉gdi + 就是个坑...真没gdi好用,我用gdi 的方式 也会闪,但是好多了.. void DoPaint(CDCHandle dc){ T * t = static_cast<T *>(this); ATLASSERT(m_pBkgndImage->get()); CRect rc; CMemDC myMemDC(dc, this); t->GetWindowRect(&rc); CGdiPlusBitmapHelper helpr (rc.Width(), rc.Height()); helpr.StretchBlt(m_pBkgndImage->get(), 0, 0, 0,0,rc.Width(),rc.Height()); //画需要镂空的三角 Color color(255,255,0,0); helpr.DrawTriang(TRIANG_PIX, color); helpr.Profile(rc, TRIANG_PIX, Color(255,0,0,0), 1); DrawTitle(t, helpr);//画标题 Graphics g(&myMemDC.GetDC()); g.SetSmoothingMode(SmoothingModeAntiAlias); g.DrawImage(helpr.get(), 0 , 0 , rc.Width(), rc.Height());} 我有些怀疑 Graphics::DrawImage 的速度... 背景贴图的 程序我做过,用的GDI双缓冲,没闪烁过,怎么用了GDI+ 一个劲儿的闪 我这个是 WTL, 用的GDI + ...CDCHandle 是WTL 里面的CDC 的一个类GDI+和GDI混合使用:不管用的MFC还是WTL,标准的WINDOWS API都是支持的RECT rc; GetWindowRect(m_hWnd, &rc); int nWidth=rc.right-rc.left; int nHeight=rc.bottom-rc.top; HDC hMemDC=CreateCompatibleDC(dc.m_hDC); HBITMAP hMemBitmap=CreateCompatibleBitmap(dc.m_hDC, nWidth, nHeight); HBITMAP hOldBitmap=(HBITMAP)SelectObject(hMemDC, hMemBitmap); //在内存DC画图 Graphics g(hMemDC); g.DrawImage(&image, 0, 0, nWidth, nHeight); //贴到窗口DC上 BitBlt(dc.m_hDC, 0, 0, nWidth, nHeight, hMemDC, 0, 0, SRCCOPY); SelectObject(hMemDC, hOldBitmap); //释放GDI资源 DeleteDC(hMemDC); DeleteObject(hMemBitmap);DrawImage效率的确不咋的 我这个是 WTL, 用的GDI + ...CDCHandle 是WTL 里面的CDC 的一个类GDI+和GDI混合使用:不管用的MFC还是WTL,标准的WINDOWS API都是支持的RECT rc; GetWindowRect(m_hWnd, &rc); int nWidth=rc.right-rc.left; int nHeight=rc.bottom-rc.top; HDC hMemDC=CreateCompatibleDC(dc.m_hDC); HBITMAP hMemBitmap=CreateCompatibleBitmap(dc.m_hDC, nWidth, nHeight); HBITMAP hOldBitmap=(HBITMAP)SelectObject(hMemDC, hMemBitmap); //在内存DC画图 Graphics g(hMemDC); g.DrawImage(&image, 0, 0, nWidth, nHeight); //贴到窗口DC上 BitBlt(dc.m_hDC, 0, 0, nWidth, nHeight, hMemDC, 0, 0, SRCCOPY); SelectObject(hMemDC, hOldBitmap); //释放GDI资源 DeleteDC(hMemDC); DeleteObject(hMemBitmap);DrawImage效率的确不咋的 是的....我全部改成用 GDI 的方式了。。 闪烁消失了.... 我这个是 WTL, 用的GDI + ...CDCHandle 是WTL 里面的CDC 的一个类GDI+和GDI混合使用:不管用的MFC还是WTL,标准的WINDOWS API都是支持的RECT rc; GetWindowRect(m_hWnd, &rc); int nWidth=rc.right-rc.left; int nHeight=rc.bottom-rc.top; HDC hMemDC=CreateCompatibleDC(dc.m_hDC); HBITMAP hMemBitmap=CreateCompatibleBitmap(dc.m_hDC, nWidth, nHeight); HBITMAP hOldBitmap=(HBITMAP)SelectObject(hMemDC, hMemBitmap); //在内存DC画图 Graphics g(hMemDC); g.DrawImage(&image, 0, 0, nWidth, nHeight); //贴到窗口DC上 BitBlt(dc.m_hDC, 0, 0, nWidth, nHeight, hMemDC, 0, 0, SRCCOPY); SelectObject(hMemDC, hOldBitmap); //释放GDI资源 DeleteDC(hMemDC); DeleteObject(hMemBitmap);DrawImage效率的确不咋的 是的....我全部改成用 GDI 的方式了。。 闪烁消失了....姜还是老的辣! 大侠过来帮忙啊 _ConnectionPtr::CreateInstance问题 在对话框中显示50多张图片,如何解决? VC++中的CToolTipCtrl提示信息出现慢(好像要等一秒),怎么让它快一点显示出来呢? 给我几个好点的VC++的网站 VC经常不能保存文件,导致文件丢失 怎样学习VC及其他(这个问题对我值100分) ActiveX 的使用问题 求救,RDS的问题,我的中间层注册已经成功,但是创建对象时出错,提示:internet server出错。 如何改变菜单的背景? 现在想学MFC,想从宏观上有些认识,恳请赐教 XML ffmpeg 计算内存中的帧的dts、pts问题
另外,窗口创建完毕后调用UpdateWindow可能有效果。Windows GDI坑比较多,在不同系统上表现也不一致,还是多试试看吧。
双缓冲绘图,HDC hMemDC, hBITMAP hMemBitmap;
{
T * t = static_cast<T *>(this); ATLASSERT(m_pBkgndImage->get());
CRect rc;
CMemDC myMemDC(dc, this);
t->GetWindowRect(&rc); CGdiPlusBitmapHelper helpr (rc.Width(), rc.Height());
helpr.StretchBlt(m_pBkgndImage->get(), 0, 0, 0,0,rc.Width(),rc.Height()); //画需要镂空的三角
Color color(255,255,0,0);
helpr.DrawTriang(TRIANG_PIX, color);
helpr.Profile(rc, TRIANG_PIX, Color(255,0,0,0), 1); DrawTitle(t, helpr);//画标题 Graphics g(&myMemDC.GetDC());
g.SetSmoothingMode(SmoothingModeAntiAlias);
g.DrawImage(helpr.get(), 0 , 0 , rc.Width(), rc.Height());
}
我有些怀疑 Graphics::DrawImage 的速度... 背景贴图的 程序我做过,用的GDI双缓冲,没闪烁过,怎么用了GDI+ 一个劲儿的闪
GDI+和GDI混合使用:
不管用的MFC还是WTL,标准的WINDOWS API都是支持的RECT rc;
GetWindowRect(m_hWnd, &rc);
int nWidth=rc.right-rc.left;
int nHeight=rc.bottom-rc.top;
HDC hMemDC=CreateCompatibleDC(dc.m_hDC);
HBITMAP hMemBitmap=CreateCompatibleBitmap(dc.m_hDC, nWidth, nHeight);
HBITMAP hOldBitmap=(HBITMAP)SelectObject(hMemDC, hMemBitmap);
//在内存DC画图
Graphics g(hMemDC);
g.DrawImage(&image, 0, 0, nWidth, nHeight);
//贴到窗口DC上
BitBlt(dc.m_hDC, 0, 0, nWidth, nHeight, hMemDC, 0, 0, SRCCOPY);
SelectObject(hMemDC, hOldBitmap);
//释放GDI资源
DeleteDC(hMemDC);
DeleteObject(hMemBitmap);DrawImage效率的确不咋的
GDI+和GDI混合使用:
不管用的MFC还是WTL,标准的WINDOWS API都是支持的RECT rc;
GetWindowRect(m_hWnd, &rc);
int nWidth=rc.right-rc.left;
int nHeight=rc.bottom-rc.top;
HDC hMemDC=CreateCompatibleDC(dc.m_hDC);
HBITMAP hMemBitmap=CreateCompatibleBitmap(dc.m_hDC, nWidth, nHeight);
HBITMAP hOldBitmap=(HBITMAP)SelectObject(hMemDC, hMemBitmap);
//在内存DC画图
Graphics g(hMemDC);
g.DrawImage(&image, 0, 0, nWidth, nHeight);
//贴到窗口DC上
BitBlt(dc.m_hDC, 0, 0, nWidth, nHeight, hMemDC, 0, 0, SRCCOPY);
SelectObject(hMemDC, hOldBitmap);
//释放GDI资源
DeleteDC(hMemDC);
DeleteObject(hMemBitmap);DrawImage效率的确不咋的
是的....我全部改成用 GDI 的方式了。。 闪烁消失了....
GDI+和GDI混合使用:
不管用的MFC还是WTL,标准的WINDOWS API都是支持的RECT rc;
GetWindowRect(m_hWnd, &rc);
int nWidth=rc.right-rc.left;
int nHeight=rc.bottom-rc.top;
HDC hMemDC=CreateCompatibleDC(dc.m_hDC);
HBITMAP hMemBitmap=CreateCompatibleBitmap(dc.m_hDC, nWidth, nHeight);
HBITMAP hOldBitmap=(HBITMAP)SelectObject(hMemDC, hMemBitmap);
//在内存DC画图
Graphics g(hMemDC);
g.DrawImage(&image, 0, 0, nWidth, nHeight);
//贴到窗口DC上
BitBlt(dc.m_hDC, 0, 0, nWidth, nHeight, hMemDC, 0, 0, SRCCOPY);
SelectObject(hMemDC, hOldBitmap);
//释放GDI资源
DeleteDC(hMemDC);
DeleteObject(hMemBitmap);DrawImage效率的确不咋的
是的....我全部改成用 GDI 的方式了。。 闪烁消失了....
姜还是老的辣!