结贴了 经过多方改动
终于可以显示了
在wm_create里是显示不出来的,要在wm_paint中
代码贴出:
void DrawImage(HWND hwnd,LPCWSTR lpName,LPCWSTR lpType,int left,int top)
{
HDC hdc=GetDC(hwnd);
HMODULE hModule_Current=GetModuleHandle(NULL);
HRSRC hr=FindResource(hModule_Current,MAKEINTRESOURCE(IDP_IMAGE),_T("JPG"));
if(hr==NULL)
return;
DWORD dwsize=SizeofResource(GetModuleHandle(NULL),hr);
HGLOBAL hg=LoadResource(GetModuleHandle(NULL),hr);
LPSTR lp=(LPSTR)LockResource(hg);
RECT rect;
rect.top = top;
rect.left=left;
IImagingFactory *pImageFactory=NULL;
IImage *pImage;
if(SUCCEEDED(CoInitializeEx(NULL,COINIT_MULTITHREADED)))
{
HRESULT hResult=0;
if(SUCCEEDED(hResult=CoCreateInstance(CLSID_ImagingFactory,NULL,CLSCTX_INPROC_SERVER,IID_IImagingFactory,(void**)&pImageFactory)))
{
hResult=0;
if(SUCCEEDED(pImageFactory->CreateImageFromBuffer(lp,dwsize,DISPOSAL_NONE,&pImage)))
{
ImageInfo imgInf;
pImage->GetImageInfo(&imgInf);
rect.right=rect.left+imgInf.Width;
rect.bottom=397;
pImage->Draw(hdc,&rect,NULL);
pImage->Release();
}
else MessageBox(hwnd,_T("create fail"),_T("error"),MB_OKCANCEL);
pImageFactory->Release();
}
else
MessageBox(hwnd,_T("CoCreateInstance fail"),_T("error"),MB_OKCANCEL);
if(hResult==REGDB_E_CLASSNOTREG)
MessageBox(hwnd,_T("REGDB_E_CLASSNOTREG"),_T("error"),MB_OKCANCEL);
CoUninitialize();
}
DeleteObject(hr);
}
wm_paint:
hdc = BeginPaint(hWnd, &ps);
// TODO: 在此添加任意绘图
DrawImage(hWnd,MAKEINTRESOURCE(IDP_IMAGE),_T("JPG"),0,0);
EndPaint(hWnd, &ps);
break;
在此谢谢各位了
再问:能否再做出些特效:旋转 或者轮流显示多张图片?