Max
Max

Reputation: 1360

BitBlt draws a blank image

I'm using MFC, and I'm trying to draw an image to the screen. I've got the following OnDraw function:

void CgraphicstestView::OnDraw(CDC* pDC)
{
 CgraphicstestDoc* pDoc = GetDocument();
 ASSERT_VALID(pDoc);
 if (!pDoc)
  return;

 m_Bitmap.LoadBitmap(IDB_WALL); // m_Bitmap is a CBitmap member of CgraphicstestView
                                   // IDB_WALL is a .png resource
 CDC dcMemory;
 dcMemory.CreateCompatibleDC(pDC);
 dcMemory.SelectObject(&m_Bitmap);
 pDC->BitBlt(10, 10, 32, 32, &dcMemory, 0, 0, SRCCOPY);
}

This will draw to the screen, but the destination area is blank. BitBlt is working, since changing SRCCOPY to BLACKNESS draws a black rectangle. Anyone see what I'm missing?

Upvotes: 0

Views: 1397

Answers (1)

Benjamin Lindley
Benjamin Lindley

Reputation: 103693

I would have to guess that the problem is that your image is somehow invalid. Because I tested it and it works fine. LoadBitmap returns an HBITMAP, so you could test it like this:

HBITMAP hresult = m_Bitmap.LoadBitmap(IDB_WALL);
assert(hresult);

Upvotes: 1

Related Questions