COLORREF crl;
GetWindowRect(&m_rtWnd);
CRgn wndRgn, rgnTemp;
CDC* pDC = GetWindowDC();
CDC dcCompatible;
dcCompatible.CreateCompatibleDC(pDC);
CBitmap* pOldBitmap = dcCompatible.SelectObject(&m_bitmap);
wndRgn.CreateRectRgn(0,0,m_rtWnd.Width(),m_rtWnd.Height());
for(int x=0; x<m_rtWnd.Width(); x++)
{
for(int y=0; y<m_rtWnd.Height(); y++)
{
crl = dcCompatible.GetPixel(x, y);
if(crl == TRANSCOLOR)
{
rgnTemp.CreateRectRgn(x, y, x+1, y+1);
wndRgn.CombineRgn(&wndRgn,&rgnTemp, RGN_XOR);//裁减掉透明色区域
rgnTemp.DeleteObject();
}
}
}
//设置最终的窗口范围
SetWindowRgn((HRGN)wndRgn,TRUE);
dcCompatible.SelectObject(pOldBitmap);
ReleaseDC(pDC);
ReleaseDC(&dcCompatible);
转载于:https://www.cnblogs.com/rogee/archive/2011/04/02/2003314.html