程序目前编译都OK
但执行后没有显示*.BMP
要把*.BMP添加到哪里,可以让程序调用

解决方案 »

  1.   

    自己读BMP文件,然后在OnDraw或OnPaint里显示.
      

  2.   

    可以将bmp文件导入进资源里 ResourceView中->导入->bmp
      

  3.   

    First,read bmp file from files to memoryvoid CBMPViewerDoc::OnFileOpen() 
    {
    // TODO: Add your command handler code here
    LPCTSTR lpszFilter="BMP Files(*.bmp)|*.bmp|任何文件|*.*||";
    CFileDialog dlg1(TRUE,lpszFilter,NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,lpszFilter,NULL);
    CString filename;
    CFile file;
    BITMAPFILEHEADER bf; //打开文件对话框
    if(dlg1.DoModal()==IDOK)
    {
    filename=dlg1.GetPathName();
    if(file.Open(filename,CFile::modeRead|CFile::shareDenyNone,NULL)==0)
    {
    //读取文件失败
    AfxMessageBox("无法打开文件!",MB_OK,0);
    return;
    }
    //读取文件头
    file.Read(&bf,sizeof(bf));
    //判断是否是BMP文件
    if(bf.bfType!=0x4d42)//'BM'
    {
    AfxMessageBox("非BMP文件!",MB_OK,0);
    return;
    }
    //判断文件是否损坏
    if(file.GetLength()!=bf.bfSize)
    {
    AfxMessageBox("文件已损坏,请检查!",MB_OK,0);
    return;
    } //读文件信息头
    file.Read(&bi,sizeof(bi));

    //计算调色板数目
    numQuad=0;
    if(bi.biBitCount<24)
    {
    numQuad=1<<bi.biBitCount;
    }

    //为图像信息pbi申请空间
    pbi=(BITMAPINFO*)HeapAlloc(GetProcessHeap(),0,sizeof(BITMAPINFOHEADER)+numQuad*sizeof(RGBQUAD));
    memcpy(pbi,&bi,sizeof(bi));
    quad=(RGBQUAD*)((BYTE*)pbi+sizeof(BITMAPINFOHEADER));

    //读取调色板
    if(numQuad!=0)
    {
    file.Read(quad,sizeof(RGBQUAD)*numQuad);
    }

    //为图像数据申请空间
    bi.biSizeImage=bf.bfSize-bf.bfOffBits;
    lpBuf=(BYTE*)HeapAlloc(GetProcessHeap(),0,bi.biSizeImage);
    //读取图像数据
    file.Read(lpBuf,bi.biSizeImage);

    //图像读取完毕,关闭文件,设置标志
    file.Close();
    flag=1;
    zoomfactor=1;
    lpshowbuf=NULL;
    PrepareShowdata();
    UpdateAllViews(NULL,0,NULL);
    }
    }Second ,to draw the bmp on the device contextvoid CBMPViewerView::OnPaint() 
    {
    CPaintDC dc(this); // device context for painting

    // TODO: Add your message handler code here
    //得到文档指针
    CBMPViewerDoc* pDoc = GetDocument();
    ASSERT_VALID(pDoc); //是否已打开某个BMP文件
    if(pDoc->flag==1)
    {
    //指定是显示的颜色
    SetDIBitsToDevice(dc.m_hDC,0,0,pDoc->pbi->bmiHeader.biWidth,
    pDoc->pbi->bmiHeader.biHeight,0,0,0,
    pDoc->pbi->bmiHeader.biHeight,pDoc->lpshowbuf, 
    pDoc->pbi,DIB_RGB_COLORS);   
    }
    // Do not call CView::OnPaint() for painting messages
    }
      

  4.   

    我把*.jpg文件强行转化为*.bmp文件后
    bmp文件无法导入进资源里 ResourceView中