位图文件一般用LoadImage来装入,而CFileDialog一般只是给出你选的文件名

解决方案 »

  1.   

    void CDemoDlg::OnBtnOpen() 
    {  
        CDC *pDC=GetDC(); BITMAPFILEHEADER bmfh;
    BITMAPINFOHEADER bmih; CFileDialog dlg(TRUE,"*.bmp","001.bmp",OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
         "BMP Files(dlg*.bmp)|*.bmp||");

    CString msg;
    int iResult;
    iResult=dlg.DoModal();
    if(iResult==IDOK)
    {
    CString msg;
    msg+=dlg.GetFileName();
    }

    CFile *fp;
    fp=new CFile();
    fp->Open(msg,CFile::modeRead);
    fp->SeekToBegin();
    fp->Read(&bmfh,sizeof(bmfh));
    fp->Read(&bmih,sizeof(bmih)); RGBTRIPLE * rgb=new RGBTRIPLE[bmih.biWidth*bmih.biHeight];
    fp->SeekToBegin();
    fp->Seek(54,CFile::begin);
    fp->Read(rgb,bmih.biWidth*bmih.biHeight*3);
        

    }
    fp->Close();
    delete fp;
    delete rgb;
    }
      

  2.   

    void CDemoDlg::OnPaint() 
    {
    if (IsIconic())
    {
    CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle
    int cxIcon = GetSystemMetrics(SM_CXICON);
    int cyIcon = GetSystemMetrics(SM_CYICON);
    CRect rect;
    GetClientRect(&rect);
    int x = (rect.Width() - cxIcon + 1) / 2;
    int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon
    dc.DrawIcon(x, y, m_hIcon);
    }
    else
    {
    CDialog::OnPaint();
    }
    if(!bitmap.m_hObject)
    return;
    CRect rct;
    m_image.GetClientRect(&rct);
    HDC hDC = pDC->GetSafeHdc();

    SetStretchBltMode(hDC,HALFTONE); BITMAPINFO  bitmapInfo;
    bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    bitmapInfo.bmiHeader.biWidth = bmp.bmWidth;
    bitmapInfo.bmiHeader.biHeight = bmp.bmHeight;
    bitmapInfo.bmiHeader.biPlanes = 1;
    bitmapInfo.bmiHeader.biBitCount = 24;
    bitmapInfo.bmiHeader.biCompression = BI_RGB;
    bitmapInfo.bmiHeader.biClrUsed =0; StretchDIBits(hDC,0,0,rct.Width(),rct.Height(),0,bmp.bmHeight,bmp.bmWidth,-bmp.bmHeight,rgb,&bitmapInfo,DIB_RGB_COLORS,SRCCOPY);
    }