www.pudn.com > SDKSkin.rar > RNHDC.cpp
#include "stdafx.h"
#include "RNHDC.h"
RNHDC::RNHDC(HDC hDc_,bool bDel)
{
m_bDel = bDel;
Attach(hDc_,bDel);
}
RNHDC::RNHDC(HWND hWnd_,DCTYPE flag,bool bDel)
{
m_bDel = bDel;
m_hWnd = hWnd_;
if(0 != m_hWnd)
{
if(DC_NOR == flag)
{
m_hDc = GetDC(m_hWnd);
}
else
{
m_hDc = GetWindowDC(m_hWnd);
}
}
}
HDC RNHDC::Detach()
{
HDC tmDc = m_hDc;
m_hDc = 0;
m_hWnd = 0;
return tmDc;
}
void RNHDC::Attach(HDC hDc_,bool bDel)
{
Clear();
m_bDel = bDel;
m_hDc = hDc_;
m_hWnd = 0;
}
RNHDC::~RNHDC()
{
Clear();
}
void RNHDC::Clear()
{
if(m_bDel == false) return;
if(0 == m_hDc) return;
if(0 != m_hWnd)
{
ReleaseDC(m_hWnd,m_hDc);
}
else
{
DeleteDC(m_hDc);
}
}
bool RNHDC::IsValid()
{
if(0 == m_hDc) return false;
return true;
}
HWND RNHDC::GetHwnd()
{
if(0 != m_hWnd)
{
return m_hWnd;
}
}