• <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)  編輯 收藏 引用 所屬分類: 代碼片段分享
            久久国产亚洲高清观看| 久久无码国产| 久久91精品国产91久久户| 久久精品国产亚洲av影院| 91精品国产91久久久久福利| 91精品国产综合久久四虎久久无码一级| 久久精品9988| 欧美日韩精品久久久免费观看| 亚洲精品无码专区久久久| 久久久久久午夜成人影院| 久久久网中文字幕| 国内精品人妻无码久久久影院| 99久久婷婷国产综合精品草原| 久久国产欧美日韩精品| 国产日韩久久免费影院| 成人久久免费网站| 国产综合成人久久大片91| 亚洲国产精品久久久天堂| 99久久久久| 97r久久精品国产99国产精| 色综合久久夜色精品国产| 日韩精品国产自在久久现线拍| 亚洲欧美伊人久久综合一区二区| 久久人妻少妇嫩草AV蜜桃| www性久久久com| 亚洲欧美成人综合久久久| 久久久久亚洲AV成人网人人网站| 久久99精品久久久久久噜噜| 久久国产精品无码HDAV| 伊人久久大香线蕉亚洲| 亚洲国产综合久久天堂| 精品久久久久久99人妻| 一级做a爱片久久毛片| 97久久精品人妻人人搡人人玩| 国色天香久久久久久久小说| 久久综合久久伊人| 成人精品一区二区久久| 久久久精品视频免费观看| 久久99久久无码毛片一区二区| 国产成人无码精品久久久久免费| 欧美777精品久久久久网|