问题出在你创建的Bitmap上,一般情况下用CreateCompatibleBitmap来创建,但是这时候创建的Bitmap跟DC走了,是16位色的,这样就会丢失了Alpha通道。所以应该这样:
RECT rtWnd;
hWnd = GetSafeHwnd();
if(hWnd == NULL)
break;
if(!::GetWindowRect(hWnd, &rtWnd))
break;
hWndDC = ::GetDC(hWnd);
if(hWndDC == NULL)
break;
hMemDC = ::CreateCompatibleDC(hWndDC);
if(hMemDC == NULL)
break;
//hMemBitmap = ::CreateCompatibleBitmap(hWndDC, rtWnd.right - rtWnd.left, rtWnd.bottom - rtWnd.top); ////这样就会失败
BYTE* pBits = NULL;
BITMAPINFOHEADER bmih = { sizeof (BITMAPINFOHEADER) };
bmih.biWidth = rtWnd.right - rtWnd.left;
bmih.biHeight = rtWnd.bottom - rtWnd.top ;
bmih.biPlanes = 1 ;
bmih.biBitCount = 32; //这里一定要是32
bmih.biCompression = BI_RGB ;
bmih.biSizeImage = 0 ;
bmih.biXPelsPerMeter = 0 ;
bmih.biYPelsPerMeter = 0 ;
bmih.biClrUsed = 0 ;
bmih.biClrImportant = 0 ;
hMemBitmap = CreateDIBSection (NULL, (BITMAPINFO *)&bmih, DIB_RGB_COLORS, (VOID**)&pBits, NULL, 0) ;
if(hMemBitmap == NULL)
break;