• <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): 代碼片段分享
            久久99免费视频| 亚洲精品乱码久久久久久按摩 | 国产精品熟女福利久久AV| 9久久9久久精品| 国内精品欧美久久精品| 亚洲va久久久久| 999久久久免费精品国产| 国产精品九九久久免费视频| 青青青青久久精品国产h久久精品五福影院1421 | 老司机午夜网站国内精品久久久久久久久 | 99久久精品免费看国产一区二区三区 | 一本色道久久88综合日韩精品 | 国内精品九九久久久精品| 久久天天躁狠狠躁夜夜2020 | 久久久亚洲欧洲日产国码是AV| 久久亚洲日韩精品一区二区三区| 久久久国产精品福利免费| 一级A毛片免费观看久久精品| 久久久久高潮毛片免费全部播放| 国产午夜电影久久| 久久成人国产精品| 亚洲精品国产第一综合99久久| 国产精品青草久久久久福利99 | 国产精品美女久久久久久2018| 久久久久久久久久久免费精品| 精品无码久久久久国产| 久久亚洲精品成人无码网站| 久久久久久亚洲精品无码| 久久精品国内一区二区三区| 国内精品综合久久久40p| 狠狠精品久久久无码中文字幕 | 狠狠色丁香婷婷久久综合不卡| 亚洲精品乱码久久久久久久久久久久| 久久乐国产精品亚洲综合| 国产精品熟女福利久久AV| www亚洲欲色成人久久精品| 久久精品国产亚洲AV大全| 午夜精品久久久久久中宇| 成人综合久久精品色婷婷 | 69久久夜色精品国产69| 久久人人爽人人爽人人片av高请|