MFC使用双缓存之后图像仍旧闪烁

自学的双缓存,不知道写的对不对,希望大神帮看一下~

void CTTSDlg::OnPaint()
{
CPaintDC dc(this);
CDC MemDC;
CBitmap MemBitmap;
CRect PaintRect;

    // 双缓冲绘图  
    GetClientRect(PaintRect);
    if (MemDC.CreateCompatibleDC(&dc))
    {
        if (MemBitmap.CreateCompatibleBitmap(&dc, PaintRect.Width(), PaintRect.Height()))
        {
            if (HGDIOBJ OldObject = MemDC.SelectObject(MemBitmap))
            {
                // 拷贝背景图, 以处理透明色  
                if (MemDC.BitBlt(0, 0, PaintRect.Width(), PaintRect.Height(), &dc, 0, 0, SRCCOPY))
                {
                    Gdiplus::Graphics g(MemDC);

                    // Paint here ...  
                    DrawGameRange(MemDC);
                    DrawSnake(MemDC);
                    DrawFood(MemDC);

                    dc.BitBlt(0, 0, PaintRect.Width(), PaintRect.Height(), &MemDC, 0, 0, SRCCOPY);
                }
                MemDC.SelectObject(OldObject);
            }
            MemBitmap.DeleteObject();
        }
        MemDC.DeleteDC();
    }

    CDialogEx::OnPaint();

}


重载OnEraseBkgnd函数(WM_ERASEBKGNG),让它直接返回 TRUE