在View窗口中创建一个需要常显的Dialog(用于显示各种信息),当View用Bitblt不断刷新时,Dialog闪烁非常严重!
应如何解决??

解决方案 »

  1.   

    可以只刷新需要重绘的区域InvalidateRect
      

  2.   

    class 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.
    };
    void CXXXXDialog::OnPaint()
    {
    CPaintDC dcPaint(this);
    CMemDC dc(&dcPaint);
    dc....(...);
    }
      

  3.   

    谢谢各位
    我再说清楚一点吧:在View上有一个浮动窗口(Dialog),当我按左右键时View中的内容需要全部更新(将在兼容DC中的内容用Bitblt复制到pDC中),由于浮动窗口是View的子窗口,所以在Bitblt时引起了浮动窗口(Dialog)重绘,故闪烁.View不闪.所以Ivalidaterect不适用,CDialogBar也不能解决问题,我本就用的是Double Buffer
      

  4.   

    我又自己解决了:
             CRect rc;
    InfoDlg.GetClientRect(&rc);
    InfoDlg.ClientToScreen(&rc);
    ScreenToClient(&rc);
    CRgn rgn;
    rgn.CreateRectRgnIndirect(rc);
    pDC->SelectClipRgn(&rgn, RGN_DIFF);
             ...
             rgn.DeleteObject();
      

  5.   

    可以指定View的属性为WS_CLIPCHILD
      

  6.   

    最终我放弃了用DialogBox,改用画矩形的办法,使用三缓冲,完全解决了闪烁问题、并且可以拖动.谢谢各位,准备结贴.
      

  7.   

    第一,双缓冲,
    第二,处理WM_ERASEBKGND消息,直接return false。注释掉原有的代码。
      

  8.   

    CRect rc;
    InfoDlg.GetClientRect(&rc);
    InfoDlg.ClientToScreen(&rc);
    ScreenToClient(&rc);
    CRgn rgn;
    rgn.CreateRectRgnIndirect(rc);
    pDC->SelectClipRgn(&rgn, RGN_DIFF);
             ...
             rgn.DeleteObject();
    这个方法不错,你的三缓冲也可以理解
      

  9.   

    闪烁通常是由于不必要的擦除背景引起的
    试试看处理WM_ERASEBKGND
      

  10.   

    一样的,进入ClassView,最后一个选项卡,把Message Filter选为Window而不是Dialog即可看到此消息了。