• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            Error

            C++博客 首頁 新隨筆 聯系 聚合 管理
              217 Posts :: 61 Stories :: 32 Comments :: 0 Trackbacks

            ////////////////////////////////////////////////////////////////

            簡介:內存DC,又名“雙緩沖”,是解決windows窗口自繪中出現“閃屏”的常規手段。

            1)、為屏幕 DC 創建兼容的內存 DC
            2)、創建位圖
            3)、把位圖選入設備環境
            4)、把繪制好的圖形“拷貝“到屏幕上

             

            看這個代碼:

            首先看構造,從一個CDC構造。然后看了一下成員函數,好像沒幾個,估計這是一個可以完全替換的CDC的省心的東東。

            然后看析構:析構是一個BitBit,聯想自己做內存DC的時候,最后一步也是內存到DC的貼圖動作。

            公開接口就兩個,重載的CDC* 和 ->操作,直接能當作CDC使用。

            這幾個細節需要注意:

            1.m_bMemDC = !pDC->IsPrinting();  // 以前關注不多,這是用于判斷這個DC是不是用于print,如果是就不使用“內存DC”,至于為什么還不了解。我理解是沒有需要。

            2.FillSolidRect(m_rect, pDC->GetBkColor());  // WM_ERASEBKGND,針對這個消息的細節處理。

             

            這個類持有了一個“前臺”DC,它本身是一個“后臺”DC,每次后臺克隆前臺執行繪畫然后把結果貼回去。

            這里還有一個細節,就是SelectObject。為了保證不泄漏,最好的辦法是,每次工作完成將所有的GDI對象復位。

            ///////////////////////////////////////////////////////////////

            class CMemDC : public CDC
            {
            public:

                // constructor sets up the memory DC
                CMemDC(CDC* pDC) : CDC()
                {
                    ASSERT(pDC != NULL);

                    m_pDC = pDC;
                    m_pOldBitmap = NULL;
            #ifndef _WIN32_WCE_NO_PRINTING
                    m_bMemDC = !pDC->IsPrinting();
            #else
                    m_bMemDC = FALSE;
            #endif

                    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);
            #ifndef _WIN32_WCE
                        SetWindowOrg(m_rect.left, m_rect.top);
            #endif
                        // EFW - Bug fix - Fill background in case the user has overridden
                        // WM_ERASEBKGND.  We end up with garbage otherwise.
                        // CJM - moved to fix a bug in the fix.
                        FillSolidRect(m_rect, pDC->GetBkColor());
                    }
                    else        // Make a copy of the relevent parts of the current DC for printing
                    {
            #if !defined(_WIN32_WCE) || ((_WIN32_WCE > 201) && !defined(_WIN32_WCE_NO_PRINTING))
                        m_bPrinting = pDC->m_bPrinting;
            #endif
                        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.
            };

            posted on 2012-10-08 10:41 Enic 閱讀(234) 評論(0)  編輯 收藏 引用 所屬分類: 代碼片段分享
            久久久久久亚洲精品不卡| 欧美精品国产综合久久| 久久久久99精品成人片欧美| 无码专区久久综合久中文字幕| 国产精品无码久久综合| 亚洲国产成人久久精品动漫| 久久久噜噜噜久久| 久久综合给合久久狠狠狠97色| 女人香蕉久久**毛片精品| 亚洲国产精品综合久久网络| 久久国产色AV免费看| 久久精品中文字幕有码| 久久久久久久亚洲Av无码| 国产亚洲成人久久| 人妻久久久一区二区三区| 国产精品xxxx国产喷水亚洲国产精品无码久久一区 | 久久久精品一区二区三区| 久久99精品久久久久久秒播| 一本色道久久88精品综合| 久久久久亚洲AV成人网人人软件| 亚洲AV日韩精品久久久久久| 久久久久国产一级毛片高清板| 天天爽天天狠久久久综合麻豆| 久久精品免费网站网| 久久99精品国产一区二区三区| 久久久久久国产精品无码下载| 精品久久久久久久久久久久久久久| 无码超乳爆乳中文字幕久久| 久久无码精品一区二区三区| 久久最新精品国产| 狠狠色丁香婷综合久久| 久久综合噜噜激激的五月天| 久久亚洲国产最新网站| 无码8090精品久久一区| 欧美与黑人午夜性猛交久久久| 狠狠色伊人久久精品综合网| 91久久福利国产成人精品| 99久久精品免费看国产| 久久精品亚洲乱码伦伦中文| 久久本道综合久久伊人| 99热热久久这里只有精品68|