我想在Dialog上显示BMP文件,该怎么做在OnPaint中么,具体怎么做???

解决方案 »

  1.   

    最简单的办法。加入bmp文件。
    加入一个picture控件。type选择bitmap,image选择插入bmp的id。
      

  2.   

    BOOL DrawState(
       CPoint pt,
       CSize size,
       CBitmap* pBitmap,
       UINT nFlags,
       CBrush* pBrush = NULL 
    );
    Parameters
    pt 
    Specifies the location of the image. 
    size 
    Specifies the size of the image. 
    hBitmap 
    A handle to a bitmap. 
    nFlags 
    Flags that specify the image type and state. See DrawState in the Platform SDK for the possible nFlags types and states. 
    hBrush 
    A handle to a brush. 
    pBitmap 
    A pointer to a Cbitmap object. 
    pBrush 
    A pointer to a Cbrush object. 
    hIcon 
    A handle to an icon. 
    lpszText 
    A pointer to text. 
    bPrefixText 
    Text that may contain an accelerator mnemonic. The lData parameter specifies the address of the string, and the nTextLen parameter specifies the length. If nTextLen is 0, the string is assumed to be null-terminated. 
    nTextLen 
    Length of the text string pointed to by lpszText. If nTextLen is 0, the string is assumed to be null-terminated. 
    lpDrawProc 
    A pointer to a callback function used to render an image. This parameter is required if the image type in nFlags is DST_COMPLEX. It is optional and can be NULL if the image type is DST_TEXT. For all other image types, this parameter is ignored. For more information about the callback function, see the DrawStateProc function in the Platform SDK. 
    lData 
    Specifies information about the image. The meaning of this parameter depends on the image type. 
    Return Value
    Nonzero if successful; otherwise 0.
      

  3.   

    An Image (GIF, JPEG, BMP, ICO, WMF and EMF) Viewer 
    http://www.vccode.com/file_show.php?id=876
      

  4.   

    CPaintDC dc(this);
    CBitmap bitmap;
    BITMAP bm;
    CDC memDC;
    memDC.CreateCompatibleDC(&dc);
    if(bitmap.LoadBitmap(bmpID))
    {
    bitmap.GetBitmap(&bm);
    memDC.SelectObject(&bitmap);
    pDC->StretchBlt(left,top,width,height,&memDC,0,0,
    bm.bmWidth,bm.bmHeight,SRCCOPY);
    }
      

  5.   

    动态载入图片
     图像控件(本例用KoDak 图像编辑控件)1.    首先应该保证系统中有这个控件。注意,它不能单独使用,必须和其他几个控件(特别是Imgcmn.dll)一同使用。如果没有,从别的机器上copy过来即可。这几个文件是Imgadmin.ocx,Imgcmn.dll,Imgedit.ocx,Imgscan.ocx,Imgshl.dll,Imgthumb.ocx,Imgutil.dll,把它们copy到windows\system目录下,然后用regsvr32.exe将它们分别注册。 2.    打开工程,进入资源管理器,在对话框上单击右键,单击Insert Activex control… 选择Kodak图象编辑控件,大小任意。 3.    在对话框上选中该控件,为其添加变量:m_ctrlPicture。。 4.    在BOOL CTestDlg::OnInitDialog()添加如下:BOOL CTestDlg::OnInitDialog(){     CDialog::OnInitDialog();     m_ctrlPicture.SetImage("aa.jpg");  //保证图像在工程目录下,也可以写绝对路径     m_ctrlPicture.Display();
         return TRUE;  // return TRUE unless you set the focus to a control                   // EXCEPTION: OCX Property Pages should return FALSE}编译运行就OK了,此种方法的好处就是可能针对多种图像格式.
    这个是在csdn上看到的
    http://dev.csdn.net/develop/article/24/24240.shtm
      

  6.   

    我需要动态的取得BMP文件,所以需要这样
    bmp.LoadBitmap("D:\0.bmp");
    但是这样后,就不能执行bmp.GetBitmap(&Bitmap);了
    如果用bmp.LoadBitmap(IDB_BITMAP1)就可以,为什么???
    // 获得设备场景
    CDC* pDC = GetDC(); // 取得位图
    CBitmap bmp;
    bmp.LoadBitmap(IDB_BITMAP1);
    // bmp.LoadBitmap("D:\\0.bmp");  为什么这样不行
    BITMAP Bitmap;
    bmp.GetBitmap(&Bitmap); // 创建内存设备场景
    CDC MemDC;
    MemDC.CreateCompatibleDC(pDC); // 将位图选入内存设备场景
    CBitmap* pOldBmp = MemDC.SelectObject(&bmp); // 创建椭圆形裁剪区并选入内存设备场景
    CRgn rgn;
    rgn.CreateRectRgn(55, 0, Bitmap.bmWidth+55, Bitmap.bmHeight);
    pDC->SelectClipRgn(&rgn); // 显示设备场景
    pDC->BitBlt(55,
    0,
    Bitmap.bmWidth,
    Bitmap.bmHeight,
    &MemDC,
    0,
    0,
    /*Bitmap.bmWidth,Bitmap.bmHeight,*/SRCCOPY); // 还原内存设备场景
    MemDC.SelectObject(pOldBmp);
    MemDC.DeleteDC();
    ReleaseDC(pDC);
      

  7.   

    刚才写错了:bmp.LoadBitmap("D:\\0.bmp");
      

  8.   

    用hImage = (HBITMAP)LoadImage( NULL, name, IMAGE_BITMAP, 0, 0, 
    LR_DEFAULTSIZE|LR_LOADFROMFILE);
    代替就可以了!