创建不规则对话框

源码下载地址: http://download.csdn.net/detail/a117653909/4704728MFC,VS2008,Win7 64位先把底图(bg.bmp)中要扣掉的部分ps成RGB(255, 0, 255)
在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 );
}


你可能感兴趣的:(创建不规则对话框)