Cool !!!! Display JPEG and GIF images in VC

zhaozj2021-02-11  218

Display JPEG and GIF images in the VC

I saw MSDN and thought it was useful for BMP, and the result is that JPG GIF can be. Pay tribute to JDK who is not trust to MS! // AdmiRe JDK The following is an experimental code, you can try at 95, I successfully on 98 IE5. CView is an example, do not forget AfxOleInit void CPICView :: OnDraw (CDC * pDC) {CPICDoc * pDoc = GetDocument (); ASSERT_VALID (pDoc); IPicture * pPic; IStream * pStm; CFileStatus fstatus; CFile file; LONG cb ; if (File.Open ("C: / Test.jpg", CFile :: ModeRead && file.getStatus ("C: / Test.jpg", FSTATUS && ((cb = fstatus.m_size)! = -1) ) {hGLOBAL hGlobal = GlobalAlloc (GMEM_MOVEABLE, cb); LPVOID pvData = NULL; if (hGlobal = NULL) {if ((pvData = GlobalLock (hGlobal)!) = NULL) {file.ReadHuge (pvData, cb);! GlobalUnlock (hGlobal); CreateStreamOnHGlobal (hGlobal, TRUE, & pStm); 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-> Ge TdeviceCaps (HORZSIZE) * 100.0); FY = (Double) PDC-> getDeviceCaps (Vertres) * (Double) hmheight / ((Double) PDC-> g etcDevicecaps (vertsize) * 100.0); if (Failed (PPIC-> Render (* PDC, 0, 0, DWOR D) FX, (DWORD) FY, 0, HMHEIGHT, HMWIDTH, -H MHEIGHT, NULL)) AFXMESSAGEBOX ("Failed to Render The Picture!"); PPIC-> Release ();} else afxMessageBox ("Error Loading Picture From stream! ");}}} Else afxMessageBox (" Can't open image file! ");

转载请注明原文地址:https://www.9cbs.com/read-4027.html

New Post(0)