|
BOOL CInfoDlg::ShowPic(HDC hdc, const TCHAR *filename, int nStartX, int nStartY, int nChangeX, int nChangeY)
{
IImagingFactory *pImgFactory = NULL;
IImage *pImage = NULL;
ImageInfo imageInfo;
RECT dstRc;
if(FAILED(CoInitializeEx(NULL,COINIT_MULTITHREADED)))
{
MessageBox(TEXT( "CoInitializeEx "));
}
if(SUCCEEDED(CoCreateInstance(CLSID_ImagingFactory,
NULL,CLSCTX_INPROC_SERVER,
IID_IImagingFactory,
(void **)&pImgFactory)))
{
if (SUCCEEDED(pImgFactory->CreateImageFromFile(filename,&pImage)))
{
pImage-> GetImageInfo(&imageInfo);
dstRc.left = nStartX;
dstRc.top = nStartY;
dstRc.right = nStartX + nChangeX;
dstRc.bottom = nStartY + nChangeY;
pImage-> Draw(hdc, &dstRc, NULL);
pImage-> Release();
}
else
{
MessageBox(TEXT( "CreateImageFromFile "));
// AfxMessageBox("CreateImageFromFile");
pImgFactory = NULL;
pImage = NULL;
CoUninitialize();
return FALSE;
}
}
else
{
MessageBox(TEXT( "CoCreateInstance "));
pImgFactory = NULL;
pImage = NULL;
CoUninitialize();
return FALSE;
}
pImgFactory = NULL;
pImage = NULL;
CoUninitialize();
return TRUE;
}
上面是我的代码,实现是在onpaint中,ShowPic(dc, _T("\\exitdown.png"), 10, 10, 24, 24);
图片是放在F:\GPS\exitdown.png 图片的路径我换过很多,也试过相对路径和绝对路径的表示,但是运行倒if (SUCCEEDED(pImgFactory->CreateImageFromFile(filename,&pImage))) 时,就跳到ELSE去运行了,弄了我很长时间,快要崩溃了,跪求大侠拔刀相助。。。。。。。。。
|
|