-
- static void DrawBitmap(UINT bitmap,CDC *pDC,CRect rect)
- {
- CBitmap bmp;
- if (bmp.LoadBitmap(bitmap))
- {
- BITMAP bmpInfo;
- bmp.GetBitmap(&bmpInfo);
- CDC dcMemory;
- dcMemory.CreateCompatibleDC(pDC);
- dcMemory.SelectObject(&bmp);
- pDC->SetStretchBltMode(HALFTONE);
- pDC->StretchBlt(rect.left,rect.top,rect.Width(),rect.Height(),&dcMemory,0,0,bmpInfo.bmWidth,bmpInfo.bmHeight,SRCCOPY);
- }
- }
-
-
- static void drawBitmapFormFile(CString BitmapFilePath,CDC *pDC,CRect rect)
- {
- HANDLE filehandle=::LoadImage(NULL,BitmapFilePath,IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
- if(filehandle!=NULL)
- {
- CBitmap bmp;
- if(bmp.Attach(filehandle))
- {
- BITMAP bmpInfo;
- bmp.GetBitmap(&bmpInfo);
- CDC dcMemory;
- dcMemory.CreateCompatibleDC(pDC);
- dcMemory.SelectObject(&bmp);
- pDC->SetStretchBltMode(HALFTONE);
- pDC->StretchBlt(rect.left,rect.top,rect.Width(),rect.Height(),&dcMemory,0,0,bmpInfo.bmWidth,bmpInfo.bmHeight,SRCCOPY);
- bmp.Detach();
- }
- }
- }
BOOL CShowBitmapView::ShowJpgGif(CDC* pDC,CString strPath, int x, int y)
- {
- IStream *pStm;
- CFileStatus fstatus;
- CFile file;
- LONG cb;
-
- if (file.Open(strPath,CFile::modeRead)&&
- file.GetStatus(strPath,fstatus)&&
- ((cb = fstatus.m_size) != -1))
- {
- HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, cb);
- LPVOID pvData = NULL;
- if (hGlobal != NULL)
- {
- pvData = GlobalLock(hGlobal);
- if (pvData != NULL)
- {
-
- file.Read(pvData, cb);
- GlobalUnlock(hGlobal);
- CreateStreamOnHGlobal(hGlobal, TRUE, &pStm);
- }
- }
- }
- else
- {
- return false;
- }
-
-
- IPicture *pPic;
-
- 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);
- double fX,fY;
-
- fX = (double)pDC->GetDeviceCaps(HORZRES)*(double)hmWidth/((double)pDC->GetDeviceCaps(HORZSIZE)*100.0);
- fY = (double)pDC->GetDeviceCaps(VERTRES)*(double)hmHeight/((double)pDC->GetDeviceCaps(VERTSIZE)*100.0);
-
- if(FAILED(pPic->Render(*pDC,x,y,(DWORD)fX,(DWORD)fY,0,hmHeight,hmWidth,-hmHeight,NULL)))
- {
- pPic->Release();
- return false;
- }
- pPic->Release();
- }
- else
- {
- return false;
- }
- return true;
- }