|
CCePngButtonST按钮类中的一个疑问
[复制链接]
BOOL CCePngButtonST::ImageFromIDResource(UINT nID, LPCTSTR sTR, IImage** pIImage)
{
HINSTANCE hInst = AfxGetResourceHandle();
HRSRC hRsrc = ::FindResource (hInst,MAKEINTRESOURCE(nID),sTR); // type
if (!hRsrc)
return FALSE;
// load resource into memory
DWORD len = SizeofResource(hInst, hRsrc);
BYTE* lpRsrc = (BYTE*)LoadResource(hInst, hRsrc);
if (!lpRsrc)
return FALSE;
// Allocate global memory on which to create stream
HGLOBAL m_hMem = GlobalAlloc(GMEM_FIXED, len);
BYTE* pmem = (BYTE*)GlobalLock(m_hMem);
memcpy(pmem,lpRsrc,len);
IStream* pStream;
CreateStreamOnHGlobal(m_hMem,FALSE,&pStream);
// load from stream
pIImgFactory->CreateImageFromStream(pStream, pIImage);
// free/release stuff
GlobalUnlock(m_hMem);
if(pStream != NULL)pStream->Release();
FreeResource(lpRsrc);
if(m_hMem != NULL) GlobalFree(m_hMem);//添加这一行之后,图片没有绘出来;如果没有这一行,占用的内存资源没有释放
if(!pIImage)
return FALSE;
return TRUE;
}
不知道是不是那个地方我修改的有问题,还是这段代码有问题
|
|