Chinaunix首页 | 论坛 | 博客
  • 博客访问: 17558
  • 博文数量: 2
  • 博客积分: 105
  • 博客等级: 民兵
  • 技术积分: 30
  • 用 户 组: 普通用户
  • 注册时间: 2009-03-29 03:29
文章分类

全部博文(2)

文章存档

2011年(1)

2009年(1)

我的朋友
最近访客

分类: WINDOWS

2009-03-29 03:29:08

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

// CDoubleBufferImpl - Provides double-buffer painting support to any window


template <class T>
class CDoubleBufferImpl
{
public:
// Overrideables

    void DoPaint(CDCHandle /*dc*/)
    {
        // must be implemented in a derived class

        ATLASSERT(FALSE);
    }

// Message map and handlers

    BEGIN_MSG_MAP(CDoubleBufferImpl)
        MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBackground)
        MESSAGE_HANDLER(WM_PAINT, OnPaint)
#ifndef _WIN32_WCE
        MESSAGE_HANDLER(WM_PRINTCLIENT, OnPaint)
#endif // !_WIN32_WCE

    END_MSG_MAP()

    LRESULT OnEraseBackground(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
    {
        return 1; // no background painting needed

    }

    LRESULT OnPaint(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& /*bHandled*/)
    {
        T* pT = static_cast<T*>(this);
        ATLASSERT(::IsWindow(pT->m_hWnd));

        if(wParam != NULL)
        {
            RECT rect = { 0 };
            pT->GetClientRect(&rect);
            CMemoryDC dcMem((HDC)wParam, rect);
            pT->DoPaint(dcMem.m_hDC);
        }
        else
        {
            CPaintDC dc(pT->m_hWnd);
            CMemoryDC dcMem(dc.m_hDC, dc.m_ps.rcPaint);
            pT->DoPaint(dcMem.m_hDC);
        }

        return 0;
    }
};

阅读(1310) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:博客已升级,请注意变更地址

给主人留下些什么吧!~~