MFC Static上显示JPG图像,如何使图像大小自适应Static边框

void CJpgDlg::OnButton1() 
{
        IStream *m_pStream;
        IPicture *m_pPictrue;
        OLE_XSIZE_HIMETRIC m_JPGWidth;
        OLE_YSIZE_HIMETRIC m_JPGHeight;
        HGLOBAL hMem;
        CFile file;
        if (!file.Open("c:\\a0.bmp",CFile::modeReadWrite))
        {
                MessageBox("open file failed!");
                return;
        }
        
        DWORD len=file.GetLength();         //这边改成内存图片数据的长度
        hMem=GlobalAlloc(GMEM_MOVEABLE,len);
        LPVOID pData=NULL;
        pData=GlobalLock(hMem);
        file.ReadHuge(pData,len);           //把这里的从文件读数据,改成从内存读数据
        file.Close();        
        
        GlobalUnlock(hMem);
        CreateStreamOnHGlobal(hMem,TRUE,&m_pStream);
        OleLoadPicture(m_pStream,len,TRUE,IID_IPicture,(LPVOID*)&m_pPictrue);
        m_pPictrue->get_Height(&m_JPGHeight);
        m_pPictrue->get_Width(&m_JPGWidth);
        CRect lpRec; 
        GetDlgItem(IDC_STATIC1)->GetWindowRect(&lpRec); 
        ScreenToClient(&lpRec);
        m_pPictrue->Render(GetDC()->m_hDC,lpRec.left,lpRec.top,lpRec.Width(),lpRec.Height(),0,m_JPGHeight,m_JPGWidth,-m_JPGHeight,NULL);	
}
原文地址:http://bbs.csdn.net/topics/380267452

你可能感兴趣的:(mfc)