I guess I do understand what happens if I select "an object" into a "device contect", and if this object is a brush, font, pen: The charactersicts of these objects are hence forth used for the drawing onto the device context.
However, I don't understand what happens after I select a bitmap into the device context, much less, why it is necessary to do so.
I have a program that somehwere does
HDC dc = ::GetDC(hWnd);
ffBitmap = ::CreateCompatibleBitmap(dc, windowWidth, windowHeight);
ffMemoryDc = ::开发者_高级运维CreateCompatibleDC(dc);
hOldBitmap = (HBITMAP) ::SelectObject(ffMemoryDc, ffBitmap);
and later draws unto the ffMemoryDc and then *BitBlt*s the ffMemoyDc into the real device context of a window.
BitBlt ( dc,
0, 0, windowWidth, windowHeight,
ffMemoryDc,
0, 0,
SRCCOPY
);
The variable ffBitmap is referenced nowhere else in the entire program, yet, if I don't SelectObject(ffBitmap), nothing is drawn, so it is necessary.
I'd appreciate if someone could shed some light what happens here.
That's how it work. The bitmap you select in the DC is the bitmap that is "painted on". Quoting MSDN:
Before an application can use a memory device context for drawing operations, it must select a bitmap of the correct width and height into the device context.
精彩评论