1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
////////////////////////////////////////////////////////////////////////// //功能:在pDC所在窗口上的DestRect区域内显示path指定的图片 //参数: // pDC:目的DC // path:目的图片的路径 // DestRect:目的区域 ////////////////////////////////////////////////////////////////////////// bool DrawBK(CDC* pDC,CString path,CRect DestRect) { if(path.IsEmpty()) return false;
IStream *pStm; CFileStatus fstatus; CFile file; LONG cb;
if(file.Open(path,CFile::modeRead)&&file.GetStatus(path,fstatus)&&((cb=fstatus.m_size)!=-1)) { HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, cb); if(hGlobal != NULL) { LPVOID pvData = GlobalLock(hGlobal); if (pvData != NULL) { file.ReadHuge(pvData, cb); GlobalUnlock(hGlobal); CreateStreamOnHGlobal(hGlobal, TRUE, &pStm); } } } else { return false; } //显示图片 IPicture *pPic; CoInitialize(NULL);
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);
//使用render函数显示图片 if(FAILED(pPic->Render(*pDC,DestRect.left,DestRect.top,DestRect.Width(),DestRect.Height(),0,hmHeight,hmWidth,-hmHeight,NULL))) { pPic->Release(); return false; } pPic->Release(); } else { return false; } CoUninitialize(); return true; }
|
近期评论