只支持静态GIF,JPEG、WMF、ICO、CUR。
void DrawPIC(HDC hDC,LPCTSTR sFile,int x,int y,int cx,int cy)
{
IPicture *pPic;
IStream *pStm; CFileStatus fstatus;
CFile file;
LONG cb; if(file.Open(sFile,CFile::modeRead) &&
file.GetStatus(sFile,fstatus) &&
((cb = fstatus.m_size) != -1))
{
HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, cb);
LPVOID pvData = NULL;
if(hGlobal != NULL)
{
if((pvData = GlobalLock(hGlobal)) != NULL)
{
file.ReadHuge(pvData, cb);
GlobalUnlock(hGlobal);
CreateStreamOnHGlobal(hGlobal, TRUE,&pStm); if(SUCCEEDED(OleLoadPicture(pStm,fstatus.m_size,
TRUE,IID_IPicture,(LPVOID* )&pPic)))
{
OLE_XSIZE_HIMETRIC hmWidth;
OLE_YSIZE_HIMETRIC hmHeight;
pPic->get_Width(&hmWidth);
pPic->get_Height(&hmHeight);
int fX,fY;
if((cx==-1)||(cy==-1))
{
fX = MulDiv(hmWidth, GetDeviceCaps(hDC,LOGPIXELSX), 2540);
fY = MulDiv(hmHeight, GetDeviceCaps(hDC,LOGPIXELSX), 2540);
}
else
{
fX = cx;fY = cy;
}
if(FAILED(pPic->Render(hDC,x,y,(DWORD)fX,(DWORD)fY,0,hmHeight,hmWidth,-hmHeight,NULL)))
AfxMessageBox("Failed To Render The picture!");
pPic->Release();
}
else
AfxMessageBox("Error Loading Picture From Stream!");
}
}
}
else
AfxMessageBox("Can't Open Image File!");
}
void DrawPIC(HDC hDC,LPCTSTR sFile,int x,int y,int cx,int cy)
{
IPicture *pPic;
IStream *pStm; CFileStatus fstatus;
CFile file;
LONG cb; if(file.Open(sFile,CFile::modeRead) &&
file.GetStatus(sFile,fstatus) &&
((cb = fstatus.m_size) != -1))
{
HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, cb);
LPVOID pvData = NULL;
if(hGlobal != NULL)
{
if((pvData = GlobalLock(hGlobal)) != NULL)
{
file.ReadHuge(pvData, cb);
GlobalUnlock(hGlobal);
CreateStreamOnHGlobal(hGlobal, TRUE,&pStm); if(SUCCEEDED(OleLoadPicture(pStm,fstatus.m_size,
TRUE,IID_IPicture,(LPVOID* )&pPic)))
{
OLE_XSIZE_HIMETRIC hmWidth;
OLE_YSIZE_HIMETRIC hmHeight;
pPic->get_Width(&hmWidth);
pPic->get_Height(&hmHeight);
int fX,fY;
if((cx==-1)||(cy==-1))
{
fX = MulDiv(hmWidth, GetDeviceCaps(hDC,LOGPIXELSX), 2540);
fY = MulDiv(hmHeight, GetDeviceCaps(hDC,LOGPIXELSX), 2540);
}
else
{
fX = cx;fY = cy;
}
if(FAILED(pPic->Render(hDC,x,y,(DWORD)fX,(DWORD)fY,0,hmHeight,hmWidth,-hmHeight,NULL)))
AfxMessageBox("Failed To Render The picture!");
pPic->Release();
}
else
AfxMessageBox("Error Loading Picture From Stream!");
}
}
}
else
AfxMessageBox("Can't Open Image File!");
}
在codeproject.com上也有。如果要多一点,你就必须用一些专门的Dll来完成。也可以在那个站点找到。当然使用GDI+也是一个非常好的选择。