void ImageFromIDResource(CImage& image, UINT nID, LPCTSTR lpType) { HINSTANCE hInst = g_hInst; HRSRC hRsrc = ::FindResource (hInst,MAKEINTRESOURCE(nID),lpType); if(hRsrc == NULL) return; DWORD dwLen = SizeofResource(hInst, hRsrc); BYTE* lpRsrc = (BYTE*)LoadResource(hInst, hRsrc); if (!lpRsrc) return;; HGLOBAL m_hMem = GlobalAlloc(GMEM_FIXED, dwLen); BYTE* pmem = (BYTE*)GlobalLock(m_hMem); memcpy(pmem,lpRsrc,dwLen); IStream* pstm; CreateStreamOnHGlobal(m_hMem,FALSE,&pstm); image.Load(pstm); GlobalUnlock(m_hMem); pstm->Release(); FreeResource(lpRsrc); }
相关文章: