|
void LoadImageFromRes(HDC hDC,DWORD ImgID,HINSTANCE inst,RECT&rec)
{
HINSTANCE OldHinstance = AfxGetResourceHandle();
AfxSetResourceHandle(inst);
CoInitializeEx(NULL, COINIT_MULTITHREADED);
IImagingFactory *g_pImgFactory;
//COM初始化省略
IImage *pImage;
SUCCEEDED(CoCreateInstance (CLSID_ImagingFactory, NULL,CLSCTX_INPROC_SERVER, IID_IImagingFactory, (void **)&g_pImgFactory));
//装载资源
HRSRC hr;//资源句柄
hr = FindResource(AfxGetResourceHandle(),MAKEINTRESOURCE(ImgID),_T("PNG"));
HGLOBAL hglobal= LoadResource(AfxGetResourceHandle(), hr );
LPVOID lpVoid = NULL;
lpVoid = LockResource(hglobal);
int nSize = 0;
nSize = (UINT)SizeofResource(AfxGetResourceHandle(), hr);
if(nSize <= 0){return ;}
HRESULT ret1 =g_pImgFactory-> CreateImageFromBuffer((BYTE*)hglobal, nSize, BufferDisposalFlagNone ,&pImage);
RECT rect;
rect.left=rec.left;
rect.top=rec.top;
rect.right=rec.right;
rect.bottom=rec.bottom;
//画picture到DC中
pImage->Draw(hDC, &rect, NULL);
UnlockResource(hglobal);
pImage->Release();
g_pImgFactory->Release();
AfxSetResourceHandle(OldHinstance);
} |
|