如何把一个图片加载为对话框的背景图片

解决方案 »

  1.   

    在onpaint中调用楼上的方法加载
      

  2.   

    对话框的资源编辑器上有一个picture控件,加到对话框上,查看属性,Type中选上Bitmap,再指定一个图像文件,就可以了。
      

  3.   

    我的意思是如何把一个文件abc.bmp作为对话框的背景显示。
    使用到那些对象和方法?
      

  4.   

    如果动态加载的话
    GDI函数
    HBITMAP LoadBitmap(
      HINSTANCE hInstance,  // handle to application instance
      LPCTSTR lpBitmapName  // address of bitmap resource name
    );
    等。
      

  5.   

    在onpaint函数中添加如下代码:CPaintDC dc(this);
    CRect rect;
    GetClientRect(&rect);//得到窗体的大小
    CDC dcMem; 
    dcMem.CreateCompatibleDC(&dc); 
    CBitmap bmpBackground;
    bmpBackground.LoadBitmap(IDB_BITMAPBACKGROUND);//加载背景图片
    BITMAP bitMap;
    bmpBackground.GetBitmap(&bitMap);
    CBitmap *pbmpOld=dcMem.SelectObject(&bmpBackground);
    dc.StretchBlt(0,0,rect.Width(),rect.Height(),&dcMem,0,0,bitMap.bmWidth,bitMap.bmHeight,SRCCOPY);//画窗体如果相同大小可用BitBlt
      

  6.   

    在网上下载别人做好的Dib类,诸如CmyDib等,可以达到你的要求,或者你自己去读文件,显示。
      

  7.   

    可以用函数
    HANDLE LoadImage(
      HINSTANCE hinst,   // handle of the instance containing the image
      LPCTSTR lpszName,  // name or identifier of image
      UINT uType,        // type of image
      int cxDesired,     // desired width
      int cyDesired,     // desired height
      UINT fuLoad        // load flags
    );
    例子:
    HBITMAP bitmap;
    bitmap=(HBITMAP)LoadImage(AfxGetInstanceHandle(),
    filename,IMAGE_BITMAP, 
    m_rectDst.right-m_rectDst.left,m_rectDst.bottom-m_rectDst.top,
     LR_LOADFROMFILE|LR_CREATEDIBSECTION);