在OnInitdialog里
bmp_Seperator.LoadBitmap( IDB_SEPERATOR );
if ( bmp_Seperator.GetSafeHandle() )
{
CRect nocheck_rc(0,0,500,300); //这个是bg.bmp的size
RegionWindow( &bmp_Seperator, nocheck_rc.left, nocheck_rc.top, nocheck_rc.right, nocheck_rc.bottom );
}
void CxxxDlg::RegionWindow( CBitmap* p, int left, int top, int right, int bottom )
{
CDC memDC;
memDC.CreateCompatibleDC( GetDC() );
CBitmap* pOldBitmap = memDC.SelectObject( p );
CRgn rgnWnd, rgnTemp;
CRect rectWnd;
GetWindowRect( &rectWnd );
rgnWnd.CreateRectRgn( 0, 0, rectWnd.Width(), rectWnd.Height() );
COLORREF color;
for ( long x = left; x < right; x ++ )
{
for ( long y = top; y < bottom; y ++ )
{
color = memDC.GetPixel( x, y );
if ( color == RGB(255,0,255) ) //Seperator.bmp中要抠掉的颜色
{
rgnTemp.CreateRectRgn( x, y, x+1, y+1 );
rgnWnd.CombineRgn( &rgnWnd, &rgnTemp, RGN_XOR );
rgnTemp.DeleteObject();
}
}
}
memDC.SelectObject( pOldBitmap );
SetWindowRgn( (HRGN)rgnWnd,TRUE );
}