关于SelectObject的用法
我在做个类似于幻灯片的程序,为了防止显示时的闪烁问题,我想把图先保存到内存中,然后在画到屏幕上,但有一些看不懂,还请高手赐教!!
void Bitmap::Draw(HDC hDC, int x, int y)
{
if (m_hBitmap != NULL)
{
// Create a memory device context for the bitmap
HDC hMemDC = CreateCompatibleDC(hDC);
// Select the bitmap into the device context
HBITMAP hOldBitmap = (HBITMAP)SelectObject(hMemDC, m_hBitmap);
/*这句意思是把图先会到内存中吗,那SelectObject是什么作用,为什么要生成一个hOldBitmap的句柄??*/
// Draw the bitmap to the destination device context
BitBlt(hDC, x, y, GetWidth(), GetHeight(), hMemDC, 0, 0, SRCCOPY);
// Restore and delete the memory device context
SelectObject(hMemDC, hOldBitmap);
/*始终看不懂这句话是什么意思,不是要恢复内存的初始状态吗,上一句BitBlt在将内存中的图绘到屏幕上时,内存中的图应该还在吧,那为什么要恢复呢??*/
DeleteDC(hMemDC);
}
请赐教,谢谢!