MFC中View显示框架

//View类
    int m_nDCHeight;
    int m_nDCWidth;
    HBITMAP m_hBmp;
    HBITMAP m_hOldBmp;
    CDC m_memDC;
    
    BYTE *m_pFrontBuffer;         // 内存buffer
===============================
//OnSize()
    if (cx < 1 || cy < 1)
    {
        return;
    }
    
    m_nDCHeight = cy;
    m_nDCWidth = cx;
    m_nDCWidth = ((m_nDCWidth + 3) / 4) * 4;

    BITMAPINFO bmpInfo;
    bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    bmpInfo.bmiHeader.biWidth = m_nDCWidth;
    bmpInfo.bmiHeader.biHeight = m_nDCHeight;
    bmpInfo.bmiHeader.biPlanes = 1;
    bmpInfo.bmiHeader.biBitCount = 24;
    bmpInfo.bmiHeader.biCompression = BI_RGB;
    bmpInfo.bmiHeader.biSizeImage = 0;
    bmpInfo.bmiHeader.biXPelsPerMeter = 0;
    bmpInfo.bmiHeader.biYPelsPerMeter = 0;
    bmpInfo.bmiHeader.biClrUsed = 0;
    bmpInfo.bmiHeader.biClrImportant = 0;

    if (m_hBmp)
    {
        SelectObject(m_memDC.m_hDC, m_hOldBmp);
        m_hOldBmp = NULL;
        DeleteObject(m_hBmp);
        m_hBmp = NULL;
    }
    m_hBmp = CreateDIBSection(m_memDC.m_hDC, &bmpInfo, DIB_RGB_COLORS, (void **) &m_pFrontBuffer, NULL, 0);
    m_hOldBmp = (HBITMAP)::SelectObject(m_memDC.m_hDC, m_hBmp);
===============================
//OnCreate()
    CDC *pDC = GetDC();
    m_memDC.CreateCompatibleDC(pDC);
    ReleaseDC(pDC);
===============================
//OnDraw()
BitBlt(pDC->m_hDC, m_scrollStaPos.cx, m_scrollStaPos.cy, m_nDCWidth, m_nDCHeight, m_memDC.m_hDC, 0, 0, SRCCOPY);

//OnMouseMove()
//一般在这里进行数据读写
memset(m_pFrontBuffer, 0, m_nDCWidth * m_nDCHeight * 3);
Invalidate(FALSE);
===============================
原文地址:https://www.cnblogs.com/autumoonchina/p/5755750.html