我要自绘一个按钮,加上自己的图片,形状不规则,白色是透明色. 我在OnDrawItem用CRgn 设定了有效区域,但用bitblt把图片画上去的时候,总是把白色透明的部分也画了上去. 如何令bitblt只画CRgn的区域?

解决方案 »

  1.   

    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