2009年12月25日 星期五

CuPaintDC - A device-context class.

// A device-context class. 
// A CuPaintDC object can only be used when responding to a WM_PAINT message

CuPaintDC dc(hWnd);
// CuPaintDC.h

class CuPaintDC
{
    HWND m_hWnd;
    HDC m_hDC;
    PAINTSTRUCT m_PS;
public:
    CuPaintDC(HWND hWnd);
public:
    ~CuPaintDC(void);
    operator HDC() const;
};


// CuPaintDC.cpp

CuPaintDC::CuPaintDC(HWND hWnd)
{
    m_hWnd = hWnd;
    m_hDC = BeginPaint(m_hWnd, &m_PS);
}

CuPaintDC::~CuPaintDC(void)
{
    EndPaint(m_hWnd, &m_PS);
}

CuPaintDC::operator HDC() const
{
    return m_hDC;
}

1 則留言: