Creates a memory device context that is compatible with the device specified by pDC.
该函数创建一个与指定设备兼容的内存设备上下文环境(DC)
BOOL CreateCompatibleDC( CDC* pDC );
A memory device context (内存设备上下文) is a block of memory that represents a display surface. It can be used to prepare images in memory before copying them to the actual device surface of the compatible device.
This function can only be used to create compatible device contexts for devices that support raster (光栅)operations. See the CDC::BitBlt member function for information regarding bit-block transfers between device contexts. To determine whether a device context supports raster operations, see the RC_BITBLT raster capability in the member function CDC::GetDeviceCaps.
// This handler loads a bitmap from system resources, // centers it in the view, and uses BitBlt() to paint the bitmap // bits. void CDCView::DrawBitmap(CDC* pDC) { // load IDB_BITMAP1 from our resources CBitmap bmp; if (bmp.LoadBitmap(IDB_BITMAP1)) { // Get the size of the bitmap//获取图片信息——大小 BITMAP bmpInfo; bmp.GetBitmap(&bmpInfo); // Create an in-memory DC compatible with the // display DC we're using to paint CDC dcMemory; dcMemory.CreateCompatibleDC(pDC); // Select the bitmap into the in-memory DC CBitmap* pOldBitmap = dcMemory.SelectObject(&bmp); // Find a centerpoint for the bitmap in the client area//为什么要获取中心点 CRect rect; GetClientRect(&rect); int nX = rect.left + (rect.Width() - bmpInfo.bmWidth) / 2; int nY = rect.top + (rect.Height() - bmpInfo.bmHeight) / 2; // Copy the bits from the in-memory DC into the on- // screen DC to actually do the painting. Use the centerpoint // we computed for the target offset. pDC->BitBlt(nX, nY, bmpInfo.bmWidth, bmpInfo.bmHeight, &dcMemory, 0, 0, SRCCOPY); dcMemory.SelectObject(pOldBitmap); } else { TRACE0("ERROR: Where's IDB_BITMAP1?\n"); } }