Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1620229
  • 博文数量: 441
  • 博客积分: 20087
  • 博客等级: 上将
  • 技术积分: 3562
  • 用 户 组: 普通用户
  • 注册时间: 2006-06-19 15:35
文章分类

全部博文(441)

文章存档

2014年(1)

2012年(1)

2011年(8)

2010年(16)

2009年(15)

2008年(152)

2007年(178)

2006年(70)

分类: C/C++

2006-11-22 08:52:16

// 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 the resources.
  CBitmap bmp;
  if (bmp.LoadBitmap(IDB_BITMAP1))
  {
    // Get the size of the bitmap.
    BITMAP bmpInfo;
    bmp.GetBitmap(&bmpInfo);

    // Create an in-memory device context compatible with the
    // display device context that is used to paint.
    CDC dcMemory;
    dcMemory.CreateCompatibleDC(pDC);

    // Select the bitmap into the in-memory device context.
    CBitmap* pOldBitmap = dcMemory.SelectObject(&bmp);

    // Find a center point 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 device context to the on-
    // screen device context to do the painting. Use the computed center
    // point for the target offset.
    pDC->BitBlt(nX, nY, bmpInfo.bmWidth, bmpInfo.bmHeight, &dcMemory,
      0, 0, SRCCOPY);

    dcMemory.SelectObject(pOldBitmap);
  }
  else
    TRACE0("ERROR: Where is IDB_BITMAP1?\n");
}
阅读(644) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~