Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Chapter 8 GDI Orientation and Transformations Visual C++ and MFC Fundamentals



  1. Change its ID to IDB_LADY

  2. Add a message handler of the WM_PAINT message for the CBitmap1View class
    and implement it as follows:


void CBitmap1View::OnPaint()
{
CPaintDC dc(this); // device context for painting

// TODO: Add your message handler code here
CBitmap BmpLady;
CDC MemDCLady;

// Load the bitmap from the resource
BmpLady.LoadBitmap(IDB_LADY);
// Create a memory device compatible with the above CPaintDC variable
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);
// Do not call CView::OnPaint() for painting messages
}


  1. Test the application

  2. Return to MSVC

Free download pdf