如题目。   自己写的一个小程序,用来查看外部bmp图片,查看得是一个view , 能够显示,只不过,在显示得时候,如果拉动窗口得滚动条得话,屏幕闪得非常得厉害了。   想过用双内存得方法,不过双内存都是在内存dc 里面绘制一些直线什么得,但是怎么样在内存里面得dc 中贴一张图片,能够保证频繁刷新得时候屏幕也不剧烈闪动呢?   请高人指教啊,多谢了先。

解决方案 »

  1.   

    用双缓冲
    参考MSDN中的DrawCli示例(MFC)
      

  2.   

    CDC mem;
    bm2=new CBitmap;
    bm2->CreateBitmap ();
    mem.SelectObject(bm2);
    m_pDC->BitBlt(0,0,rctClient.Width(),rctClient.Height(),&mem,0,0,SRCCOPY);
      

  3.   

    // This class implements a memory Device Contextclass CMemDC : public CDC
    {
    public: // constructor sets up the memory DC
    CMemDC(CDC* pDC) : CDC()
    {
    ASSERT(pDC != NULL);
    m_pDC = pDC;
    m_pOldBitmap = NULL;
    m_bMemDC = !pDC->IsPrinting(); if (m_bMemDC)    // Create a Memory DC
    {
    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);
    }
    else        // Make a copy of the relevent parts of the current DC for printing
    {
    m_bPrinting = pDC->m_bPrinting;
    m_hDC       = pDC->m_hDC;
    m_hAttribDC = pDC->m_hAttribDC;
    }
    } // Destructor copies the contents of the mem DC to the original DC
    ~CMemDC()
    {
    if (m_bMemDC) 
    {    
    // Copy the offscreen bitmap onto the screen.
    m_pDC->BitBlt(m_rect.left, m_rect.top, m_rect.Width(), m_rect.Height(),
    this, m_rect.left, m_rect.top, SRCCOPY); //Swap back the original bitmap.
    SelectObject(m_pOldBitmap);
    } else {
    // All we need to do is replace the DC with an illegal value,
    // this keeps us from accidently deleting the handles associated with
    // the CDC that was passed to the constructor.
    m_hDC = m_hAttribDC = NULL;
    }
    } // Allow usage as a pointer
    CMemDC* operator->() {return this;}
    // Allow usage as a pointer
    operator CMemDC*() {return this;}private:
    CBitmap  m_bitmap;      // Offscreen bitmap
    CBitmap* m_pOldBitmap;  // bitmap originally found in CMemDC
    CDC*     m_pDC;         // Saves CDC passed in constructor
    CRect    m_rect;        // Rectangle of drawing area.
    BOOL     m_bMemDC;      // TRUE if CDC really is a Memory DC.
    };