1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
void DrawPics(HDC hdc,HBITMAP image)
{
HDC hMemDC=NULL, hTempDC=NULL;
BLENDFUNCTION bf;
HBITMAP hBitmapTemp=NULL, hBitmapOld1=NULL, hBitmapOld2=NULL;
hMemDC = CreateCompatibleDC(hdc);
hTempDC = CreateCompatibleDC(hdc);
hBitmapTemp = CreateCompatibleBitmap(hdc, 24, 24);
hBitmapOld1 = (HBITMAP)SelectObject(hTempDC, hBitmapTemp);
//while transparency, clear the contents with the source background
BitBlt(hTempDC, 0, 0, 24, 24, hdc, 0, 0, SRCCOPY);
hBitmapOld2 = (HBITMAP)SelectObject(hMemDC, image);
bf.BlendOp = AC_SRC_OVER;
bf.BlendFlags = 0;
bf.SourceConstantAlpha = 255;
bf.AlphaFormat = AC_SRC_ALPHA;
AlphaBlend(hTempDC, 0, 0, 24, 24, hMemDC, 0, 0, 24, 24, bf);
//now hTempDC is ready, blt it directly on hdc
BitBlt(hdc, 0, 0, 24, 24, hTempDC, 0, 0, SRCCOPY);
SelectObject(hMemDC, hBitmapOld2);
SelectObject(hTempDC, hBitmapOld1);
DeleteObject(hBitmapTemp);
DeleteDC(hTempDC);
DeleteDC(hMemDC);
}
|