让我们先看一下 CDC::CreateCompatibleDC 的备注:
When a memory device context is created, GDI automatically selects a 1-by-1 monochrome stock bitmap for it.
意思是,当一个内存设备上下文被创建之后,GDI自动为它选入一张1*1的单色位图。这么一来,就无法直接在上面进行绘制工作了。
再来看一下CDC::CreateCompatibleBitmap 备注:
The bitmap has the same number of color planes or the same bits-per-pixel format as the specified device context.
意思是说,创建的兼容位图和指定的设备上下文具有相同的颜色平面和像素位数。
这样一来,把兼容位图选入内存兼容设备上下文后,就可以在内存设备上进行绘制了。
用完之后,记得调用DeleteObject方法将其删除。
关于双缓冲绘图,请自行查阅。