MFC使用双缓冲实现绘制字符串防闪烁

有时在性能比较低的操作系统上实现绘制文字实时变化时,会出现字体闪烁问题,下面通过双缓冲技术,先的要显示的文字绘制到缓冲区,然后再将显示出来,代码如下:

CClientDC dc(this);

CDC MemDC;

MemDC.CreateCompatibleDC(&dc);

CFont * pold_font=MemDC.SelectObject(&Font2);

CSize txtpot=MemDC.GetTextExtent(strMsg);

int x = 341-txtpot.cx;

int y = 308;

MemDC.SetBkColor(RGB(255,255,255));

MemDC.SetTextColor(RGB(0,0,0));

CBitmap MemBitmap;

MemBitmap.CreateCompatibleBitmap(&dc,txtpot.cx,txtpot.cy);

CBitmap *pOldBit=MemDC.SelectObject(&MemBitmap);

MemDC.TextOutA(0,0,strMsg);

MemDC.SelectObject(pold_font);

dc.BitBlt(x,y,txtpot.cx,txtpot.cy,&MemDC,0,0,SRCCOPY);

MemBitmap.DeleteObject();

MemDC.DeleteDC();

技术交流请加群:996775415

相关推荐
General_G15 分钟前
创建型模式—原型(Prototype)模式
c++·设计模式·原型模式
syagain_zsx15 分钟前
protobuf 实战:从 .proto 到 C++ 序列化的完整链路
c++·学习·程序人生·谷歌·protobuf
welfare9621 小时前
新号别搞:C++_list
开发语言·c++
xiaoye-duck1 小时前
《C++ 项目:手写大模型接入 SDK》云端 API 调用基础与 Apifox 调试实战
网络·c++·语言模型
坤坤子吖1 小时前
Linux 线程同步与互斥——条件变量与线程同步
linux·开发语言·c++·笔记·学习
杜 硕1 小时前
从零开始的C++生活——第二讲——03
c++·生活
布莱克6052 小时前
QtWidgets 与 QML:两大 UI 开发框架的全面对比
开发语言·c++·qt·ui·架构
hetao17338373 小时前
2026-10-20 hetao1733837 的刷题记录
c++·算法
x10n94 小时前
微软 VC++ 运行库合集VCRedistPack
开发语言·c++·microsoft·vc++运行库·dll报错
qz_Serene4 小时前
C++:string(底层,常用接口,具体题目,模拟实现)
开发语言·c++