簡易 bitmap ビューア

  CPaintDC dc(this);

  HBITMAP hBMP, hOld;
  CString csBMPFile(_T("sample.bmp"));

  hBMP = (HBITMAP)::LoadImage(AfxGetInstanceHandle(), (LPCTSTR)csBMPFile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE|LR_CREATEDIBSECTION);
  if (!hBMP)
    return;

  CDC memDC;
  memDC.CreateCompatibleDC(&dc);
  hOld = (HBITMAP)memDC.SelectObject(hBMP);

  DIBSECTION ds;
  ::GetObject(hBMP, sizeof(DIBSECTION), &ds);

  dc.BitBlt(0, 0, ds.dsBm.bmWidth, ds.dsBm.bmHeight, &memDC, 0, 0, SRCCOPY);

  memDC.SelectObject(hOld);
  ::DeleteObject(hBMP);


VC覚書きページ...