|
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;
// Allocate global storage space
HGLOBAL hGlobal = GlobalAlloc (GMEM_MOVEABLE, dwFileSize);
LPVOID pvData = NULL;
if (hGlobal == NULL)
return E_FAIL;
if ((pvData = GlobalLock (hGlobal)) == NULL) // lock allocated memory block
return E_FAIL;
memcpy (pvData, lpstr, dwFileSize);
GlobalUnlock (hGlobal);
CreateStreamOnHGlobal (hGlobal, TRUE,&pStm);
// Load graphic file
bResult = OleLoadPicture (pStm, dwFileSize, TRUE, IID_IPicture, (LPVOID *)&pPic);
if (FAILED (bResult))
return E_FAIL;
OLE_XSIZE_HIMETRIC hmWidth; // The true width of the picture
OLE_YSIZE_HIMETRIC hmHeight; // The true height of the picture
pPic-> get_Width (&hmWidth);
pPic-> get_Height (&hmHeight);
// Output graphics to the screen (somewhat like 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;
}
} |
|