// 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;
}
愈簡單的地方, 愈容易實施封裝, 那還等什麼!
回覆刪除