如何在VC中显示透明背景位图

简单的调用系统API。

Windows NT/2000/XP: Included in Windows 2000 and later.
Windows 95/98/Me: Included in Windows 98 and later.
Header: Declared in Wingdi.h; include Windows.h.
Library: Use Msimg32.lib.

void CTransparentBltTestDlg::OnPaint()
{
    CPaintDC dc(this); // device context for painting
   
    CDialog::OnPaint();
    COLORREF crMask = RGB(0x00,0x00,0xff); // Mask color of bitmap
    BITMAP bm;
    m_bmp.GetBitmap(&bm);
    int nWidth = bm.bmWidth;
    int nHeight = bm.bmHeight;
    CDC ImageDC;
    ImageDC.CreateCompatibleDC(&dc);
    CBitmap *pOldImageBMP = ImageDC.SelectObject(&m_bmp);
    ::TransparentBlt(dc.m_hDC,50,40,nWidth,nHeight,ImageDC.m_hDC,0,0,nWidth,nHeight,crMask);
    ImageDC.SelectObject(pOldImageBMP);
    }
}

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/XP: To get extended error information, call GetLastError .

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值