• <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 閱讀(227) 評論(0)  編輯 收藏 引用 所屬分類: 代碼片段分享
            色欲av伊人久久大香线蕉影院| 2020国产成人久久精品| 青青青青久久精品国产h| 久久久国产精华液| 欧美午夜精品久久久久免费视 | 大蕉久久伊人中文字幕| 午夜视频久久久久一区 | 久久精品国产半推半就| 香蕉aa三级久久毛片| 精品久久久久久久| 奇米影视7777久久精品人人爽| 久久91精品久久91综合| 中文字幕乱码久久午夜| 久久激情五月丁香伊人| 久久精品国产99国产电影网| 国产aⅴ激情无码久久| 色综合久久久久综合99| 97久久精品国产精品青草| 18禁黄久久久AAA片| 久久丝袜精品中文字幕| 91精品国产综合久久四虎久久无码一级 | 亚洲伊人久久成综合人影院 | 99久久中文字幕| 亚洲精品乱码久久久久久蜜桃图片| 国产成人无码精品久久久久免费| 精品国产乱码久久久久久1区2区| 亚洲午夜无码久久久久小说| 久久久久久青草大香综合精品| 7国产欧美日韩综合天堂中文久久久久| 久久91精品国产91久| 久久99久久成人免费播放| 久久精品国产亚洲一区二区| 国产精品99久久精品| 丰满少妇人妻久久久久久| 久久99精品久久久久久hb无码| 亚洲精品乱码久久久久久久久久久久 | 97久久精品人妻人人搡人人玩| 亚洲精品乱码久久久久久| 久久久精品人妻一区二区三区蜜桃 | 久久久久一本毛久久久| 久久99精品国产麻豆婷婷|