|
发表于 2020-4-7 21:00:01
|
显示全部楼层
HRESULT CMySocket::ShowPicBuffer(char *lpstr,int nScrWidth,int nScrHeight,long dwFileSize)
{
HDC hDC_Temp=GetDC((CWnd *)AfxGetMainWnd()->m_hWnd);
IPicture *pPic;
IStream *pStm;
BOOL bResult;
//分配全局存储空间
HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, dwFileSize);
LPVOID pvData = NULL;
if (hGlobal == NULL)
return E_FAIL;
if ((pvData = GlobalLock(hGlobal)) == NULL)//锁定分配内存块
return E_FAIL;
memcpy(pvData,lpstr,dwFileSize);
GlobalUnlock(hGlobal);
CreateStreamOnHGlobal(hGlobal, TRUE, &pStm);
//装入图形文件
bResult=OleLoadPicture(pStm,dwFileSize,TRUE,IID_IPicture,(LPVOID*)&pPic);
if(FAILED(bResult))
return E_FAIL;
OLE_XSIZE_HIMETRIC hmWidth;//图片的真实宽度
OLE_YSIZE_HIMETRIC hmHeight;//图片的真实高度
pPic->get_Width(&hmWidth);
pPic->get_Height(&hmHeight);
//将图形输出到屏幕上(有点像BitBlt)
bResult=pPic->Render(hDC_Temp,0,0,nScrWidth,nScrHeight,0,hmHeight,hmWidth,-hmHeight,NULL);
pPic->Release();
if (SUCCEEDED(bResult))
{
return S_OK;
}
else
{
return E_FAIL;
}
} |
|