我看到论坛上说是要的,但为什么MSDN上的例子没有呢?Example// This OnDraw() handler loads a bitmap from system resources,
// centers it in the view, and uses BitBlt() to paint the bitmap
// bits.void CBlat2View::OnDraw(CDC* pDC)
{
   CBlat2Doc* pDoc = GetDocument();
   ASSERT_VALID(pDoc);   // 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");
}

解决方案 »

  1.   

    MSDN只是给你参考代码,
    它当然说了,不过是在其它地方:The CreateCompatibleDC function can only be used with devices that support raster operations. An application can determine whether a device supports these operations by calling the GetDeviceCaps function. When you no longer need the memory DC, call the DeleteDC function. 
      

  2.   

    呵呵如果你非要不DeleteDC,也没什么办法其实程序这个东西本来就是这样没什么不可以、不可能只有不推荐……
      

  3.   

    一般要用DeleteDC来释放空间,这样程序稳定性要高一些!
      

  4.   

    个人觉得Create了就应该DeleteObject,呵呵,安全一点,再说,DeleteObject也不会出错,不DeleteObject在98下可能会出错,尤其是经常操作的程序段中含有这个!我遇到过!
      

  5.   

    别用那个了。什么年代了。用CImage,省事。
      

  6.   

    MSDN中的这个例子确实没有,因为在CDC的析构函数中执行了::DeleteDC(hdc),但是在我们的程序习惯还是要自己执行 CDC::DeleteDC()