在采用雙緩沖解決屏幕閃爍問題時,我在OnDraw(CDC* pDC)函數呀寫入如下代碼
 CDC MemDC;
 CBitmap bm;
 MemDC.CreateCompatibleDC(NULL);
 bm.CreateCompatibleBitmap(pDC,rc.Width(),rc.Height());
 CBitmap *pOldbm = NULL;
 pOldbm = MemDC.SelectObject(&bm);
 CBrush   brush(RGB(255,255,255));
  MemDC.FillRect(rc,&brush);
 MemDC.Move();
  MemDC.LineTo();
編譯則提示 type 'CDC' does not have an overloaded member 'operator ->'
   我在網上查找的資料大多數都是用上面的類似代碼解決的,我想我是不是哪裡寫錯了,請問我這種重載的問題應該如何處理呢!!
謝了?

解决方案 »

  1.   

    给你一个CMemDC类class CMemDC : public CDC
    {
    public:
    CMemDC(CDC* pDC) : CDC()
    {
    m_pDC = pDC;
    m_pOldBitmap = NULL;
    pDC->GetClipBox(&m_rect);
    CreateCompatibleDC(pDC);
    m_bitmap.CreateCompatibleBitmap(pDC, m_rect.Width(), m_rect.Height());
    m_pOldBitmap = SelectObject(&m_bitmap);
    SetWindowOrg(m_rect.left, m_rect.top);
    }

    ~CMemDC()
    {
    m_pDC->BitBlt(m_rect.left, m_rect.top, m_rect.Width(), m_rect.Height(),
    this, m_rect.left, m_rect.top, SRCCOPY);
    SelectObject(m_pOldBitmap);
    }
    CMemDC* operator->() {return this;}
    operator CMemDC*() {return this;}
    public:
    CBitmap m_bitmap;
    CBitmap *m_pOldBitmap;
    CDC* m_pDC;
    CRect m_rect;
    };在你的OnDraw里面这样就行了
    CRect rc;
    pDC->GetClipBox(rc);
    CMemDC memDC(pDC);CBrush   brush(RGB(255,255,255));
    memDC.FillRect(rc, &brush);
    memDC.MoveTo(0, 0);
    MemDC.LineTo(100, 100);