class CPngFromResource
{
public:
CPngFromResource(UINT uIdRes)
{
m_Istream = NULL;
PngFromResource(uIdRes);
}
~CPngFromResource()
{
if(m_Istream)
m_Istream->Release();
}


operator IStream *()
{
return m_Istream;
}
private:
IStream *m_Istream;


IStream * PngFromResource(UINT uIdRes)
{
HRSRC hPngSrc = FindResource(AfxGetInstanceHandle(),MAKEINTRESOURCE(uIdRes),_T("PNG"));
if(hPngSrc)
{
HGLOBAL hPngGlobal = LoadResource(AfxGetInstanceHandle(),hPngSrc);
if(hPngGlobal)
{
LPVOID pSrc = LockResource(hPngGlobal);
if(pSrc)
{
ULARGE_INTEGER srcSize;  
srcSize.QuadPart = SizeofResource(AfxGetApp()->m_hInstance, hPngSrc);  
m_Istream = NULL;  
CreateStreamOnHGlobal(NULL, TRUE, &m_Istream);   
if(m_Istream)  
{  
m_Istream->SetSize(srcSize);  
DWORD cbWritten = 0;  
m_Istream->Write(pSrc, srcSize.LowPart, &cbWritten);
//VERIFY( m_Imagebg.Load(pStream) == S_OK );  
return m_Istream;
}  
}
}
}
return NULL;
}
};