my example: HBITMAP CPicture::LoadImageFromID(UINT nIDRes) { try { HMODULE hInst=GetModuleHandle(NULL); LPCTSTR lpRes = MAKEINTRESOURCE(nIDRes); HRSRC hRsrc = ::FindResource(hInst, lpRes, “JPG”); if (NULL == hRsrc) return FALSE;
HGLOBAL hGlobal = LoadResource(hInst, hRsrc);
if (NULL == hGlobal)
return FALSE;
DWORD dwSize = SizeofResource(hInst, hRsrc);
LPVOID lpData = LockResource(hGlobal);
if (NULL == lpData)
return FALSE;
// alloc memory based on file size
HGLOBAL hJPG = ::GlobalAlloc(GMEM_MOVEABLE, dwSize);
LPVOID lpJGP = ::GlobalLock(hJPG);
memcpy(lpJGP, lpData, dwSize);
::GlobalUnlock(hJPG);
//LPVOID pvData = GlobalLock(hGlobal);
//_ASSERTE(NULL != pvData);
// read file and store in global memory
LPSTREAM pstm = NULL;
// create IStream* from global memory
HRESULT hr = CreateStreamOnHGlobal(hJPG, TRUE, &pstm;);
_ASSERTE(SUCCEEDED(hr) && pstm);
// Create IPicture from image file
LPPICTURE gpPicture;
hr = ::OleLoadPicture(pstm, dwSize, FALSE, IID_IPicture, (LPVOID *)&gpPicture;);
_ASSERTE(SUCCEEDED(hr) && gpPicture);
pstm->Release();
OLE_HANDLE m_picHandle;
gpPicture->get_Handle(&m;_picHandle);
return (HBITMAP)m_picHandle;
}
catch (...)
{
}
return NULL;
} //call CPicture pic; HBITMAP hbmp=pic.LoadImageFromID(IDR_TODAY);//IDR_TODAY is jpg id (HBITMAP)::SendMessage(::GetDlgItem(this->m_hWnd,IDC_TODAY), STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hbmp);