• <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++博客 首頁(yè) 新隨筆 聯(lián)系 聚合 管理
              217 Posts :: 61 Stories :: 32 Comments :: 0 Trackbacks

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

            簡(jiǎn)介:內(nèi)存DC,又名“雙緩沖”,是解決windows窗口自繪中出現(xiàn)“閃屏”的常規(guī)手段。

            1)、為屏幕 DC 創(chuàng)建兼容的內(nèi)存 DC
            2)、創(chuàng)建位圖
            3)、把位圖選入設(shè)備環(huán)境
            4)、把繪制好的圖形“拷貝“到屏幕上

             

            看這個(gè)代碼:

            首先看構(gòu)造,從一個(gè)CDC構(gòu)造。然后看了一下成員函數(shù),好像沒(méi)幾個(gè),估計(jì)這是一個(gè)可以完全替換的CDC的省心的東東。

            然后看析構(gòu):析構(gòu)是一個(gè)BitBit,聯(lián)想自己做內(nèi)存DC的時(shí)候,最后一步也是內(nèi)存到DC的貼圖動(dòng)作。

            公開(kāi)接口就兩個(gè),重載的CDC* 和 ->操作,直接能當(dāng)作CDC使用。

            這幾個(gè)細(xì)節(jié)需要注意:

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

            2.FillSolidRect(m_rect, pDC->GetBkColor());  // WM_ERASEBKGND,針對(duì)這個(gè)消息的細(xì)節(jié)處理。

             

            這個(gè)類(lèi)持有了一個(gè)“前臺(tái)”DC,它本身是一個(gè)“后臺(tái)”DC,每次后臺(tái)克隆前臺(tái)執(zhí)行繪畫(huà)然后把結(jié)果貼回去。

            這里還有一個(gè)細(xì)節(jié),就是SelectObject。為了保證不泄漏,最好的辦法是,每次工作完成將所有的GDI對(duì)象復(fù)位。

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

            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) 評(píng)論(0)  編輯 收藏 引用 所屬分類(lèi): 代碼片段分享
            久久精品国产AV一区二区三区 | 久久精品人人做人人爽电影 | 亚洲综合伊人久久大杳蕉| 思思久久好好热精品国产| 伊人久久久AV老熟妇色| 久久久久99精品成人片试看| 99麻豆久久久国产精品免费| 久久精品成人影院| 久久99国产综合精品| 国产激情久久久久影院| 狠狠色丁香婷婷久久综合五月| 久久婷婷五月综合97色一本一本 | 久久精品国产亚洲77777| 久久se精品一区二区| 热99RE久久精品这里都是精品免费| 激情伊人五月天久久综合| 亚洲伊人久久综合影院| 国产一区二区三区久久| 久久精品国产亚洲av麻豆蜜芽| 99久久国产综合精品成人影院| 老色鬼久久亚洲AV综合| 久久久久亚洲精品日久生情 | 精品多毛少妇人妻AV免费久久| 日本精品久久久久中文字幕| 国产69精品久久久久APP下载| 99久久亚洲综合精品网站| 久久久久亚洲精品无码蜜桃| 亚洲а∨天堂久久精品9966| 99久久综合国产精品二区| 国产精品久久久久久福利69堂| 久久久www免费人成精品| 亚洲欧洲久久av| 久久久久国产一级毛片高清板| 亚洲国产精品久久久久| 久久久久人妻精品一区二区三区 | 国产精品欧美久久久久天天影视 | 久久精品国产福利国产秒| 亚洲国产精品成人久久| 狠狠色丁香久久婷婷综合| 亚洲精品蜜桃久久久久久| 久久综合88熟人妻|