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