如何渲染到屏幕外缓冲区

时间:2019-06-24 13:36:49

标签: c++ mfc

我想渲染到屏幕外的缓冲区,以避免在MFC应用程序中闪烁。但是现在,我只想用某种颜色(红色)填充屏幕外缓冲区,然后将其内容复制到屏幕缓冲区中。示例代码不起作用:窗口是白色而不是红色。

void CRenderWindow::OnPaint() // CRenderWindow is derived from CDialog
{
  CRect clientRect;
  GetClientRect(&clientRect);

  // Screen DC
  CPaintDC dc(this);

  // Render to offscreen buffer
  CDC offscreenDC;
  offscreenDC.CreateCompatibleDC(&dc);
  CBitmap offscreenBuffer;
  offscreenBuffer.CreateCompatibleBitmap(&offscreenDC, clientRect.Width(), clientRect.Height());
  CBitmap *pOldBitmap = offscreenDC.SelectObject(&offscreenBuffer);

  // Fill the bitmap buffer tied to the offscreenDC with red

  COLORREF clearColor = RGB(255, 0, 0);
  offscreenDC.FillSolidRect(&clientRect, clearColor);

  // Copy the offscreen buffer's content into the screen buffer
  dc.BitBlt(clientRect.left, clientRect.top,         // Destination x&y
            clientRect.Width(), clientRect.Height(), // Source and destination w&h
            &offscreenDC,                            // Source DC
            clientRect.left, clientRect.top,         // Source x&y
            SRCCOPY);
  return;
}

我像这样覆盖了OnEraseBkgnd

BOOL CRenderWindow::OnEraseBkgnd(CDC* pDC)
{
    //return CDialog::OnEraseBkgnd(pDC);
    return TRUE;
}

0 个答案:

没有答案