如何解决vc++绘图出现屏幕闪烁的问题

 我来答
百度网友96aa8d3
2016-10-10 · TA获得超过433个赞
知道小有建树答主
回答量:2306
采纳率:75%
帮助的人:955万
展开全部
建议使用双缓冲
下面是大致的流程代码

void CGraphClass::OnPaint()
{
CPaintDC dc(this); // device context for painting

// TODO: Add your message handler code here
CRect rectClient;
GetClientRect(rectClient) ;

CDC memDC ;
CBitmap memBitmap ;
CBitmap* oldBitmap;
memDC.CreateCompatibleDC(&dc) ;
memBitmap.CreateCompatibleBitmap(&dc, rectClient.Width(), rectClient.Height());
oldBitmap = (CBitmap *)memDC.SelectObject(&memBitmap);
if (memDC.GetSafeHdc() != NULL)
{
if (m_bMonitor)
{
memDC.BitBlt(0, 0, rectClient.Width(), rectClient.Height(), &m_dcBakGround, 0, 0, SRCCOPY);
memDC.BitBlt(0, 0, rectClient.Width(), rectClient.Height(), &m_dcLine, 0, 0, SRCPAINT);
memDC.BitBlt(0, 0, rectClient.Width(), rectClient.Height(), &m_dcUpLow, 0, 0, SRCPAINT);
memDC.BitBlt(0, 0, rectClient.Width(), rectClient.Height(), &m_dcTime, 0, 0, SRCPAINT);
memDC.BitBlt(0, 0, rectClient.Width(), rectClient.Height(), &m_info, 0, 0, SRCPAINT);
memDC.BitBlt(0, 0, rectClient.Width(), rectClient.Height(), &m_otherInfo, 0, 0, SRCPAINT);
dc.BitBlt(0, 0, rectClient.Width(), rectClient.Height(), &memDC, 0, 0, SRCCOPY);
}
else
{
memDC.BitBlt(0, 0, rectClient.Width(), rectClient.Height(), &m_dcBakGround, 0, 0, SRCCOPY);
memDC.BitBlt(0, 0, rectClient.Width(), rectClient.Height(), &m_dcLine, 0, 0, SRCPAINT);
memDC.BitBlt(0, 0, rectClient.Width(), rectClient.Height(), &m_dcUpLow, 0, 0, SRCPAINT);
memDC.BitBlt(0, 0, rectClient.Width(), rectClient.Height(), &m_dcTime, 0, 0, SRCPAINT);
if (m_bWarn)
{
memDC.BitBlt(m_TimePoint.x + 30, m_TimePoint.y - 4*m_nTimeHeight, 300, 40,
&m_dcWarn,m_TimePoint.x+30, m_TimePoint.y - m_nTimeHeight*4, SRCPAINT);
}

dc.BitBlt(0, 0, rectClient.Width(), rectClient.Height(), &memDC, 0, 0, SRCCOPY);
}
}

memDC.SelectObject(oldBitmap) ;
memBitmap.DeleteObject(); //删除内存位图GDI对象
memDC.DeleteDC(); //删除内存绘图环境
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式