我写了一个MFC程序处理图像,用CFileDIalog类弹出打开框,选择要处理的图像,我设置了dlg.m_ofn.flags值使其能过一次选中多个图像(选中的图像位置可能不是连续的),怎样将选中的图像一幅一幅的加载进入内存??高手帮帮,如果有其他方法也可以,谢谢!!!

解决方案 »

  1.   

    下端代码可将一副图片显示在picture控件上。
    CRect rc;
    m_photoctl.GetWindowRect (&rc);
    IStream *pstm;
    CFileStatus fstatus;
    CFile file;
    LONG cb;
    IPicture *ppic;

    if(file.Open (m_strphotofullname,CFile::modeRead)&&file.GetStatus (m_strphotofullname,fstatus)
    && ((cb=fstatus.m_size )!=-1))
    {
    HGLOBAL hglobal=GlobalAlloc(GMEM_MOVEABLE,cb);
    LPVOID pvdata=NULL;
    if(hglobal)
    {
    if((pvdata=GlobalLock(hglobal))!=NULL)
    {
    file.ReadHuge (pvdata,cb);
    GlobalUnlock(hglobal);
    CreateStreamOnHGlobal(hglobal,true,&pstm);
    }
    }
    }

    if(SUCCEEDED(OleLoadPicture(pstm,cb,true,IID_IPicture,(LPVOID*)&ppic)))
    {
    OLE_XSIZE_HIMETRIC hmwidth;
    OLE_XSIZE_HIMETRIC hmheight;
    ppic->get_Width (&hmwidth);
    ppic->get_Height (&hmheight);
    ppic->Render (*pdc,0,0,rc.Width (),rc.Height (),0,hmheight,hmwidth,-hmheight,NULL);
    ppic->Release ();
    }若要将多幅图片加载,则循环几次即可。