我有一个基于FormView的SDI程序,我在FormView上面加载了一张BMP图片,图片的背景色也是和windows一样的灰色,在我的机器上显示的效果是FormView的颜色和图片的背景色一样的,融和比较好,可是在另一台机器上FormView的灰色和图片的背景色有深浅度的差别,看起来像补丁:(
能不能设置FormView的颜色呢?我可以得到图片的RGB,把FormView的颜色设置和图片相同?怎么做呢?

解决方案 »

  1.   

    得到了图片的RGB,你就用这个颜色来改变FormView的背景色,这样行不?
      

  2.   

    你应该在绘制位图的时候使用TransparentBlt指定一个颜色为透明色,这样的话位图的底色就变成透明了
    TransparentBlt
    The TransparentBlt function performs a bit-block transfer of the color data corresponding to a rectangle of pixels from the specified source device context into a destination device context.BOOL TransparentBlt(
      HDC hdcDest,        // handle to destination DC
      int nXOriginDest,   // x-coord of destination upper-left corner
      int nYOriginDest,   // y-coord of destination upper-left corner
      int nWidthDest,     // width of destination rectangle
      int hHeightDest,    // height of destination rectangle
      HDC hdcSrc,         // handle to source DC
      int nXOriginSrc,    // x-coord of source upper-left corner
      int nYOriginSrc,    // y-coord of source upper-left corner
      int nWidthSrc,      // width of source rectangle
      int nHeightSrc,     // height of source rectangle
      UINT crTransparent  // color to make transparent
    );
    Parameters
    hdcDest 
    [in] Handle to the destination device context. 
    nXOriginDest 
    [in] Specifies the x-coordinate, in logical units, of the upper-left corner of the destination rectangle. 
    nYOriginDest 
    [in] Specifies the y-coordinate, in logical units, of the upper-left corner of the destination rectangle. 
    nWidthDest 
    [in] Specifies the width, in logical units, of the destination rectangle. 
    hHeightDest 
    [in] Handle to the height, in logical units, of the destination rectangle. 
    hdcSrc 
    [in] Handle to the source device context. 
    nXOriginSrc 
    [in] Specifies the x-coordinate, in logical units, of the source rectangle. 
    nYOriginSrc 
    [in] Specifies the y-coordinate, in logical units, of the source rectangle. 
    nWidthSrc 
    [in] Specifies the width, in logical units, of the source rectangle. 
    nHeightSrc 
    [in] Specifies the height, in logical units, of the source rectangle. 
    crTransparent 
    [in] The RGB color in the source bitmap to treat as transparent. 
    Return Values
    If the function succeeds, the return value is TRUE.If the function fails, the return value is FALSE. Windows NT/ 2000: To get extended error information, call GetLastError. Res
    The TransparentBlt function supports all formats of source bitmaps. However, for 32 bpp bitmaps, it just copies the alpha value over. Use AlphaBlend to specify 32 bits-per-pixel bitmaps with transparency. If the source and destination rectangles are not the same size, the source bitmap is stretched to match the destination rectangle. When the SetStretchBltMode function is used, the iStretchMode modes of BLACKONWHITE and WHITEONBLACK are converted to COLORONCOLOR for the TransparentBlt function. The destination device context specifies the transformation type for the destination coordinates. The source device context specifies the transformation type for the source coordinates. TransparentBlt does not mirror a bitmap if either the width or height, of either the source or destination, is negative. Windows 98/Windows 2000: When used in a multimonitor system, both hdcSrc and hdcDest must refer to the same device or the function will fail.Requirements 
      Windows NT/2000: Requires Windows 2000 or later.
      Windows 95/98: Requires Windows 98 or later.
      Header: Declared in Wingdi.h; include Windows.h.
      Library: Included as a resource in Msimg32.dll.
      

  3.   

    可以通过处理WM_ERASEBKGND消息来改变CView、CFrameWnd或CWnd对象的背景色。
    BOOL C**View::OnEraseBkgnd(CDC* pDC) 

       // 设置所要求背景色的刷子 
       CBrush backBrush(RGB(255, 128, 128)); 
       // 保存旧刷子 
       CBrush* pOldBrush = pDC->SelectObject(&backBrush); 
       CRect rect; 
       pDC->GetClipBox(&rect);   // 擦除所需的区域 
       pDC->PatBlt(rect.left, rect.top, rect.Width(), rect.Height(), PATCOPY); 
       pDC->SelectObject(pOldBrush); 
       return TRUE; 
    }
      

  4.   

    pDC->GetClipBox(&rect);   // 擦除所需的区域 
    为什么得到的结果是0,0,0,0呢?应该得到那个区域呀?
      

  5.   

    laiyiling(最熟悉的陌生人) :
    再解释一下呀
      

  6.   

    CRect rect; //你要给他赋值的,你这样直接用就全是0了。
    CView->GetWindowRect(&rect);
    pDC->GetClipBox(&rect);   // 擦除所需的区域