First, use the TransparentBlt function
The TransparentBlt function runs in the version above Windows98/Windows2000, and it needs to include Msimg32.lib in the system, and it can be linked when used.
TransparentBlt under Windows98 will cause resource leakage, so it is not recommended to use this function under WIN98.
The TransparentBlt function prototype is as follows:
Booltransparent BLT (hdchhdcdest,//target DCint nXOriginDest,// target X offset int nYOriginDest,// target Y offset int nWidthDest, //target width int hheighdest, // target height hdchhdcsrc, //source DCint nXOriginSrc, // source X starting point int nYOriginSrc, // source Y starting point int nWidthSrc, // source width int nHeightSrc,//sourceheight uint Cr transparent//transparent color, COLORREF type); Use example:
CBitmap FootballBMP
Football BMP. load bitmap(IDB _ football BMP);
CDC ImageDC
ImageDC。 CreateCompatibleDC(pDC);
CBitmap *pOldImageBMP = ImageDC。 Select object (& soccer BMP);
Transparent BLT (PDC->; m_hDC,0,0,2 18, 199,ImageDC.m_hDC,0,0,2 18, 199,RGB(0,0,0x ff)); //RGB (0,0,0xff) changes to your background color.
ImageDC。 select object(pOldImageBMP);