Click to See Complete Forum and Search --> : Help with transparent image


dullboy
October 20th, 2006, 05:00 PM
Here is the code snipet to draw a transparent image.



void CTransparentImage::OnPaint()
{
HBITMAP l_hbmpBitmap = GetBitmap() ;

if( l_hbmpBitmap == NULL )
{
Default() ;
return ;
}

CPaintDC l_PaintDC( this ) ;
CDC l_MemoryDC ;
l_MemoryDC.CreateCompatibleDC( &l_PaintDC ) ;
CBitmap* l_pOldMemoryBitmap = l_MemoryDC.SelectObject( CBitmap::FromHandle( l_hbmpBitmap ) ) ;

CDC l_MaskDC ;
l_MaskDC.CreateCompatibleDC( &l_PaintDC ) ;
CBitmap l_MaskBitmap ;
l_MaskBitmap.CreateBitmap( l_rcClient.Width(), l_rcClient.Height(), 1, 1, NULL ) ;
CBitmap* l_pOldMaskBitmap = l_MaskDC.SelectObject( &l_MaskBitmap ) ;

l_MaskDC.BitBlt( 0, 0, l_rcClient.Width(), l_rcClient.Height(), &l_MemoryDC, 0, 0, SRCCOPY ) ;
l_PaintDC.MaskBlt(0,0, l_rcClient.Width(),l_rcClient.Height(),&l_MemoryDC,0,
0, l_MaskBitmap, 0, 0,ROP4_TRANSPARENTBLIT ) );


My question for the code snipet above is that why'd we need to call l_MaskDC.BitBlt to copy image from memory DC to mask DC? What role is mask DC playing here? Thanks for your inputs.