VC打开显示图片(百叶窗效果)

百叶窗效果图片显示:

void CDCSView::OnTimer(UINT nIDEvent)
{
 // TODO: 在此添加消息处理程序代码和/或调用默认值
 //HBITMAP hBitmap = (HBITMAP)::LoadImage(NULL, ".//res//background.bmp",
 // IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
 //if (!hBitmap)
 //{
 // KillTimer(1);
 // MessageBox("加载背景图片失败!", "错误", MB_ICONERROR);
 // return;
 //}
 //CBitmap bitmap;
 //bitmap.Attach(hBitmap);

 //CDC dcMem;
 //CClientDC dc(this);
 //dcMem.CreateCompatibleDC(&dc);
 //dcMem.SelectObject(&bitmap);

 //CRect rect;
 //GetClientRect(&rect);
 //BITMAP bmp;
 //bitmap.GetBitmap(&bmp);

 //int recty = 0;
 //int bmpy = 0;
 //int rectcy = rect.Height() / 20;
 //int bmpcy = bmp.bmHeight / 20;
 //static int nAddHeight = 0;
 //nAddHeight += 1;
 //for (int i=0; i<=20; i++)
 //{
 // //TRACE("recty = %d,rectcy = %d,nAddHeight = %d/n", recty, rectcy, nAddHeight);
 // //dc.BitBlt(0,recty,rect.Width(),nAddHeight,&dcMem,0,recty,SRCCOPY);
 // dc.StretchBlt(0,recty,rect.Width(),nAddHeight,&dcMem,0,bmpy,bmp.bmWidth,nAddHeight,SRCCOPY);
 // recty += rectcy;
 // bmpy += bmpcy;
 //}

 //if (nAddHeight >= cy)
 //{
 // KillTimer(1);
 // bIsCreate = true;
 //}


 IStream* pStm = NULL;
 IPicture* pPic = NULL;

 CString strFileName = ".//res//background.jpg";
 CFile file;
 CFileStatus fstatus;
 DWORD cb;
 if (!file.Open(strFileName, CFile::modeRead)
  || !file.GetStatus(strFileName, fstatus)
  || (cb = (DWORD)fstatus.m_size) == -1)
 {
  KillTimer(1);
  MessageBox("打开背景图片失败!", "错误", MB_ICONERROR);
  return;
 }

 HGLOBAL hGlobal = NULL;
 hGlobal = GlobalAlloc(GMEM_MOVEABLE, cb);
 if (!hGlobal)
 {
  KillTimer(1);
  MessageBox("GlobalAlloc fail!");
  return;
 }

 LPVOID pvData = NULL;
 pvData = GlobalLock(hGlobal);
 if (!pvData)
 {
  KillTimer(1);
  MessageBox("GlobalLock fail!");
  return;
 }

 file.Read(pvData, cb);
 GlobalUnlock(hGlobal);
 CreateStreamOnHGlobal(hGlobal, TRUE, &pStm);

 if(FAILED(OleLoadPicture(pStm, 0, 0, IID_IPicture, (void**)&pPic)))
 {
  KillTimer(1);
  MessageBox("OleLoadPicture fail!");
  return;
 }

 LONG x = 0;
 LONG y = 0;
 pPic->get_Width(&x);
 pPic->get_Height(&y);
 //HDC hDC = ::GetDC(m_hWnd);
 //CDC* pDC = GetDC();
 CClientDC dc(this);
 //CSize sz(x, y);
 //dc.SetMapMode(MM_HIMETRIC);
 //dc.HIMETRICtoDP(&sz);
 //TRACE("cx = %d, cy = %d/n", sz.cx, sz.cy);
 CRect rect;
 GetClientRect(&rect);

 int recty = 0;
 int jpgy = y;
 int rectcy = rect.Height() / 20;
 int jpgcy = -y / 20;
 static int nAddHeight = 0;
 nAddHeight += 1;
 int scale = y / rect.Height();
 //TRACE("%d/n", scale);
 for (int i=0; i<=20; i++)
 {
  if (FAILED(pPic->Render(dc, 0, recty, rect.Width(), nAddHeight,
    0, jpgy, x, -nAddHeight*scale, NULL)))
  {
   KillTimer(1);
   MessageBox("Render fail!");
   return;
  }
  recty += rectcy;
  jpgy += jpgcy;
 }

 if (nAddHeight >= rectcy)
 {
  KillTimer(1);
  bIsCreate = true;
 }

 pPic->Release();
 pStm->Release();
 pPic = NULL;
 pStm = NULL;
 GlobalFree(hGlobal);


 CView::OnTimer(nIDEvent);
}

更多 0
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值