1 #pragma once
2 #include "stdafx.h"
3 using namespace Gdiplus;
4
5 static bool ImageFromIDResource(UINT nID, LPCTSTR sTR,Image * &pImg)
6 {
7 HINSTANCE hInst = AfxGetResourceHandle();
8 HRSRC hRsrc = ::FindResource (hInst,MAKEINTRESOURCE(nID),sTR); // type
9 if (!hRsrc)
10 return FALSE;
11 // load resource into memory
12 DWORD len = SizeofResource(hInst, hRsrc);
13 BYTE* lpRsrc = (BYTE*)LoadResource(hInst, hRsrc);
14 if (!lpRsrc)
15 return FALSE;
16 // Allocate global memory on which to create stream
17 HGLOBAL m_hMem = GlobalAlloc(GMEM_FIXED, len);
18 BYTE* pmem = (BYTE*)GlobalLock(m_hMem);
19 memcpy(pmem,lpRsrc,len);
20 IStream* pstm;
21 CreateStreamOnHGlobal(m_hMem,FALSE,&pstm);
22 // load from stream
23 pImg=Gdiplus::Image::FromStream(pstm);
24 // free/release stuff
25 GlobalUnlock(m_hMem);
26 pstm->Release();
27 FreeResource(lpRsrc);
28 return TRUE;
29 }