如何解决vc++绘图出现屏幕闪烁的问题
1个回答
展开全部
建议使用双缓冲
下面是大致的流程代码
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(); //删除内存绘图环境
}
下面是大致的流程代码
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(); //删除内存绘图环境
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询