首页 > 代码库 > 百叶窗效果显示图片

百叶窗效果显示图片

百叶窗效果显示图片

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);}

转载自:http://blog.csdn.net/lqg1999/article/details/2237543

百叶窗效果显示图片