在 MFC 中显示多个位图

Displaying multiple bitmaps in MFC

我试图在视图中的不同位置显示同一图像的两个位图,如下所示,但它只显示第一个。如果我注释掉第一个然后显示另一个。

void CChildView::OnPaint() 
{
  // Load the bitmap
  CBitmap BmpLady;
  // Load the bitmap from the resource
  BmpLady.LoadBitmap(IDB_MB);

  CPaintDC dc(this); // device context for painting

  // Create a memory device compatible with the above CPaintDC variable
  CDC MemDCLady;
  MemDCLady.CreateCompatibleDC(&dc);

  // Select the new bitmap
  CBitmap *BmpPrevious = MemDCLady.SelectObject(&BmpLady);
  // Copy the bits from the memory DC into the current dc
  dc.BitBlt(20, 10, 436, 364, &MemDCLady, 0, 0, SRCCOPY);
  // Restore the old bitmap
  dc.SelectObject(BmpPrevious);

  // Draw another bitmap for same image.
  CPaintDC dc1(this);

  CDC MemDCLady1;
  MemDCLady1.CreateCompatibleDC(&dc1);
  CBitmap *BmpPrevious1 = MemDCLady1.SelectObject(&BmpLady);
  dc1.BitBlt(200, 100, 436, 364, &MemDCLady1, 0, 0, SRCCOPY);
  dc1.SelectObject(BmpPrevious1);
}

如何同时显示两张图片?请帮忙。提前致谢。

P.S: 我是 MFC 的新手。

第二个位图无需再次CreateCompatibleDC。通过以下更改,我可以同时显示两个位图

void CChildView::OnPaint() 
{
  CBitmap BmpLady;
  // Load the bitmap from the resource
  BmpLady.LoadBitmap(IDB_MB);

  CPaintDC dc(this);
  CDC MemDCLady;

  // Create a memory device compatible with the above CPaintDC variable
  MemDCLady.CreateCompatibleDC(&dc);
  // Select the new bitmap
  //CBitmap *BmpPrevious = MemDCLady.SelectObject(&BmpLady);
   MemDCLady.SelectObject(&BmpLady);
  // Copy the bits from the memory DC into the current dc
  dc.BitBlt(20, 10, 436, 364, &MemDCLady, 0, 0, SRCCOPY);

  // MemDCLady.SelectObject(&BmpLady);
  // Copy the bits from the memory DC into the current dc
  dc.BitBlt(200, 100, 436, 364, &MemDCLady, 0, 0, SRCCOPY);
}