If you want to load from resource use below function.
bool Utils::LoadBitmapFromPNG(UINT uResourceID, CBitmap& BitmapOut)
{
bool bRet = false;
HINSTANCE hModuleInstance = AfxGetInstanceHandle();
HRSRC hResourceHandle = ::FindResource(hModuleInstance, MAKEINTRESOURCE(uResourceID), L"PNG");
if (0 == hResourceHandle)
{
return bRet;
}
DWORD nImageSize = ::SizeofResource(hModuleInstance, hResourceHandle);
if (0 == nImageSize)
{
return bRet;
}
HGLOBAL hResourceInstance = ::LoadResource(hModuleInstance, hResourceHandle);
if (0 == hResourceInstance)
{
return bRet;
}
const void* pResourceData = ::LockResource(hResourceInstance);
if (0 == pResourceData)
{
FreeResource(hResourceInstance);
return bRet;
}
HGLOBAL hBuffer = ::GlobalAlloc(GMEM_MOVEABLE, nImageSize);
if (0 == hBuffer)
{
FreeResource(hResourceInstance);
return bRet;
}
void* pBuffer = ::GlobalLock(hBuffer);
if (0 != pBuffer)
{
CopyMemory(pBuffer, pResourceData, nImageSize);
IStream* pStream = 0;
if (S_OK == ::CreateStreamOnHGlobal(hBuffer, FALSE, &pStream))
{
CImage ImageFromResource;
ImageFromResource.Load(pStream);
pStream->Release();
BitmapOut.Attach(ImageFromResource.Detach());
bRet = true;
}
::GlobalUnlock(hBuffer);
}
::GlobalFree(hBuffer);
UnlockResource(hResourceInstance);
FreeResource(hResourceInstance);
return bRet;
}