BOOLCshowjpgdlg::showjpggif (cdc* pdc,cstring strpath,intXinty) {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; } //displays pictures in JPEG and GIF format, GIF can only display one frame, and cannot display animations .//to display an animated GIF, use the active control//components. IPicture *ppic =nullptr; //load image from file stream 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); DoubleFx,fy; //Get Image Height and widthFX = (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); //Use render function display image 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;}
2. Call
cdc* PDC = GetDlgItem (IDC_PICTRUE11)->getdc ();
Showjpggif (pdc,_t ("d.jpg"), 0,0);
VC + + display a JPG image