天天看點

使用MFC中的CDC,CBitmap來實作貼圖

void CProView::OnDraw(CDC* pDC)

{

 CProDoc* pDoc = GetDocument();

 ASSERT_VALID(pDoc);

///貼圖

CBitmap bitmap;

bitmap.LoadBitmap(IDB_BITMAP1);

CDC dcMemory;

dcMemory.CreateCompatibleDC(pDC);

// Select the bitmap into the in-memory DC

CBitmap* pOldBitmap = dcMemory.SelectObject(&bitmap);

 // Find a centerpoint for the bitmap in the client area

 RECT rect;

 GetClientRect(&rect);

 // 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(0, 0, rect.right, rect.bottom, &dcMemory,0, 0, SRCCOPY);

 dcMemory.SelectObject(pOldBitmap);

}

繼續閱讀