Adding PNG images to VC Resources
This code is a GDI + image * pimg = NULL;
Hglobal = NULL;
Hrsrc hsource = NULL;
Lpvoid = NULL;
Int nsize = 0;
Hsource = findresource (afxgetresourcehandle (), makeintresource (idr_back_png), "PNG"); // "PNG" respresent the Resource Name
If (hsource = NULL)
Return prtimg;
Hglobal = loadresource (afxgetresourcehandle (), hsource );
If (hglobal = NULL)
{
Freeresource (hglobal); Return pretimg;
}
Lpvoid = lockresource (hglobal );
If (lpvoid = NULL)
Goto exit;
Nsize = (uint) sizeofresource (afxgetresourcehandle (), hsource );
Hglobal hglobal2 = globalalloc (gmem_moveable, nsize );
If (hglobal2 = NULL)
{
Goto exit;
}
Void * pdata = globallock (hglobal2 );
Memcpy (pdata, (void *) hglobal, nsize );
Globalunlock (hglobal2 );
Istream * pstream = NULL;
If (createstreamonhglobal (hglobal2, true, & pstream) = s_ OK)
{
Pretimg = image: fromstream (pstream, false );
Pstream-> release ();
}
Freeresource (hglobal2 );
Exit:
Unlockresource (hglobal); freeresource (hglobal );
Return pretimg;