How does Bitblt() work with SRCAND?

Viewed 959

After reading theForger's "Transparent Bitmaps" tutorial for Windows API, I'm having trouble understanding the Bitblt() function with SRCAND, at a bitwise level.

Part of the code I have for drawing a single black and white bitmap with SRCAND looks like this, based from the tutorial.

BITMAP bm;
RECT rcClient;
PAINTSTRUCT ps;

HDC hdc = BeginPaint(hwnd, &ps); //hwnd = handle to current window
HDC hdcMem = CreateCompatibleDC(hdc);

GetObject(g_hbmBall, sizeof(bm), &bm); //g_hbmBall = handle to bitmap object

GetClientRect(hwnd, &rcClient);
FillRect(hdc, &rcClient, (HBRUSH)GetStockObject(LTGRAY_BRUSH));

SelectObject(hdcMem, g_hbmBall);
BitBlt(hdc, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCAND);

What I'm confused about is the last line, how with bitwise AND, the white color of a bitmap image disappears in the result while the black color stays there. (The docs for SRCAND say it "Combines the colors of the source and destination rectangles by using the Boolean AND operator.")

This is what I see visually: enter image description here

Overall, I'm wondering, at the bitwise level, what's being compared between the handle to device context in the window and the white/black image to cause the white color to disappear in the result and the black color to stay?

What I thought would happen was that, at the start, the handle to device context contains only 0s. So no matter what color would be AND'd, doing AND with 0s always results in 0s, so everything would be black in the end, resulting in a black square.

1 Answers
Related