在MFC中从打开文件对话框中选择文件如何在页面中显示缩略图,在线等

解决方案 »

  1.   

    能具体些吗,重载CFileDialog为什么就能显示缩略图了
      

  2.   

    void Add::OnButtonPhoto() 
    {
    // TODO: Add your control notification handler code here
    TCHAR strFilter[] = "Picture Files (*.bmp)|*.bmp||"; CFileDialog dlg(TRUE, ".bmp", NULL, 0, strFilter); if( dlg.DoModal() == IDOK )
    {
    m_sPhotopath = dlg.GetFileName();
    Invalidate();
    }
    }void Add::OnPaint() 
    {

    CPaintDC dc(this);
    HBITMAP bmpHandle = (HBITMAP)LoadImage(NULL,m_sPhotopath,IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
    CBitmap bmpPicture; CDC mdcPicture;
    CBitmap *bmpFromHandle = bmpPicture.FromHandle(bmpHandle);
    //获得Picture的大小
    CRect rctPicture;
    m_picture.GetWindowRect(&rctPicture);
    //获得图像大小
    BITMAP bmp;
    if(bmpFromHandle)
    bmpFromHandle->GetBitmap(&bmp);
    int nWidth = bmp.bmWidth;int nHeight = bmp.bmHeight;
    mdcPicture.CreateCompatibleDC(&dc);//申请内存
    CBitmap * bmpPrevious = mdcPicture.SelectObject(bmpFromHandle);
    ScreenToClient(&rctPicture);//坐标转换
    //缩放图像
    dc.StretchBlt(rctPicture.left, rctPicture.top, rctPicture.Width(), rctPicture.Height(),&mdcPicture, 0, 0, nWidth, nHeight, SRCCOPY);
    dc.SelectObject(bmpPrevious);
    DeleteObject(bmpHandle);//释放内存资源
    }