⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 demodlg.cpp

📁 服务端: 这是一个完整的基于Wince 4.1图形图象,网络通讯(C/S)模式下的商用程序源代码包.
💻 CPP
📖 第 1 页 / 共 5 页
字号:
		{       		    
		    ::free(imageData); 
			imageData=NULL;
			gif.close();
	     	return ;//FALSE;	
		}	 		
     //if correct then show 
	    //CClientDC dc(this);
	    CDC tmpDC;
		VERIFY(tmpDC.CreateCompatibleDC(&dc));
		//selectobject
	    HBITMAP hOldBitmap = (HBITMAP)::SelectObject(tmpDC.GetSafeHdc(), m_hBitmap);
		
	 	
		//BITMAP bminfo;
		//::GetObject(m_hBitmap,sizeof(BITMAP),&bminfo);
        //show pic bitmap 
		//VERIFY(dc.StretchBlt(0, 0, rect.Width(),rect.Height(), 
		//	                 &tmpDC, 0, 0, gi->scrWidth,gi->scrHeight,SRCCOPY));
		if(position==0)//center  
		{
          //
			int sx,sy;
			if(gi->scrWidth>=rect.Width()) sx=0;
            if(gi->scrHeight>=rect.Height()) sy=0;
			sx=(rect.Width()-gi->scrWidth)/2;
			sy=(rect.Height()-gi->scrHeight)/2;
			VERIFY(dc.BitBlt(sx, sy,gi->scrWidth,gi->scrHeight, 
			                 &tmpDC, 0, 0,SRCCOPY));
		}
		else if(position==1)//stretch,flag
		{
		  VERIFY(dc.StretchBlt(0, 0, rect.Width(),rect.Height(), 
			                 &tmpDC, 0, 0, gi->scrWidth,gi->scrHeight,SRCCOPY));
		}
		else//flat
		{
		int w,h;
		w=rect.Width();
		h=rect.Height();
        int pw,ph;
		pw=gi->scrWidth;
		ph=gi->scrHeight;
		//双缓冲
        CBitmap tmpbmp,*oldbmp;
	    CDC MemDC;		  
		//######################################################################
		MemDC.CreateCompatibleDC(&dc);          
        tmpbmp.CreateCompatibleBitmap(&dc,w,h);
        oldbmp=MemDC.SelectObject(&tmpbmp); 
	    //
         CBitmap tb,*ob;
	     CDC mdc;		  
		 //######################################################################
		 mdc.CreateCompatibleDC(&dc);          
         tb.CreateCompatibleBitmap(&dc,pw,ph);
         ob=mdc.SelectObject(&tb); 
		 //
		 VERIFY(mdc.BitBlt(0, 0,pw,ph,&tmpDC, 0, 0,SRCCOPY));
		//flat 贴图
         int xx,yy;
		 xx=w/pw;
		 yy=h/ph;
		 if(w%pw!=0) xx++;
		 if(h%ph!=0) yy++;
		 //水平方向://垂直方向
		 for(int i=0;i<xx;i++)
			 for(int j=0;j<yy;j++)
		 {
			 MemDC.BitBlt(i*pw, j*ph, pw,ph, &mdc, 0, 0, SRCCOPY);
		 }		
		 
         ////free 
         mdc.SelectObject(ob); 
         tb.DeleteObject(); 
         mdc.DeleteDC(); 
		 //
		 VERIFY(dc.BitBlt(0, 0,w,h,&MemDC, 0, 0,SRCCOPY));
		 //release resource
		 MemDC.SelectObject(oldbmp); 
         tmpbmp.DeleteObject(); 
         MemDC.DeleteDC(); 
		}
		//free
	    ::SelectObject(tmpDC.GetSafeHdc(), hOldBitmap);
		VERIFY( tmpDC.DeleteDC() ); 	            
		
	   // Invalidate(FALSE);
		//release 
	   ::DeleteObject(m_hBitmap);
		m_hBitmap=NULL;
       //Delay Time for speed
		if(fm->ctrlExt.active)			
		Sleep(fm->ctrlExt.delayTime*10);
		else
        Sleep(speed);
	  }

	 }
		//free data
	   ::free(imageData);
	    imageData=NULL;
		//关闭gif文件
        gif.close();

}
void CDemoDlg::ShowVideo(CString filename,int position)
{
	FILE *fp;
	fp=_tfopen(filename,L"rb");
	if(!fp) return;
	//init
    m_video_finished_flag=false;
	//???????????????????
	HRESULT hr;
	CRect rc;
    // Create the filter graph manager and render the file.
	//if(!m_pGraph)
	hr=CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC, IID_IGraphBuilder, (void **)&m_pGraph);
    if(FAILED(hr)) goto exit_video;//return;
   
	//Medial CONTROL
    hr=m_pGraph->QueryInterface(IID_IMediaControl, (void **)&m_pMediaControl);
	if(FAILED(hr))
	{		
        //SAFE_RELEASE(m_pGraph);        	
		goto exit_video;
	}    
	 // Filenames on Windows CE start with a \\ instead of a drive letter.
	hr = m_pGraph->RenderFile(filename, NULL);
	if(FAILED(hr))
	{
		goto exit_video;
	}

	//指定父窗体
//	IVideoWindow* pVidWin = NULL; 
	hr =m_pGraph->QueryInterface(IID_IVideoWindow, (void **)&m_pVidWin);
	if(FAILED(hr))
	{
		goto exit_video;
	}
	m_pVidWin->put_Owner((OAHWND)GetSafeHwnd());
	m_pVidWin->put_WindowStyle(WS_CHILD | WS_CLIPSIBLINGS| WS_CLIPCHILDREN);
	
	//  	
    //GetClientRect(&rc);
	//m_pVidWin->SetWindowPosition(rc.left, rc.top, rc.Width(), rc.Height());
	//  
	hr=m_pGraph->QueryInterface(IID_IBasicVideo, (void **)&pBV);
    if(FAILED(hr))
	{   
		goto exit_video;
	}
	GetClientRect(&rc);
	if(position>0)
	{     
	 hr=m_pVidWin->SetWindowPosition(rc.left, rc.top, rc.Width(), rc.Height());
	 if(FAILED(hr))
	 {   
		goto exit_video;
	 }
	}
	else//center
	{
	  LONG lHeight, lWidth;
      hr = pBV->GetVideoSize(&lWidth, &lHeight);
	  if(FAILED(hr))
	  {   
		goto exit_video;
	  }
	  int sx,sy;
	  int w,h;
	  w=rc.Width();
	  h=rc.Height();
	  if(lWidth>=w) sx=0;
	  else
        sx=(w-lWidth)/2;
	  if(lHeight>=h) sy=0;
	  else
		sy=(h-lHeight)/2;

	  //
	  hr=m_pVidWin->SetWindowPosition(sx,sy, lWidth, lHeight);
	  if(FAILED(hr))
	  {   
		goto exit_video;
	  }

	}

	//pVidWin->Release();
    // Set the owner window to receive event notices.
	// 注意此处Filter Graph Manager的事件以WM_GRAPHNOTIFY发出(用户定义的消息).
	hr=m_pGraph->QueryInterface(IID_IMediaEventEx, (void **)&m_pEvent);
	if(FAILED(hr))
	{   
		goto exit_video;
	}
	m_pEvent->SetNotifyWindow((OAHWND)GetSafeHwnd(), WM_GRAPHNOTIFY, 0);
	// 设置Seeking
	hr=m_pGraph->QueryInterface(IID_IMediaSeeking, (void **)&m_pMediaSeeking);
    if(FAILED(hr))
	{	        
		goto exit_video;
	}
	//  // Run the graph.
	
	//
    BOOL ret;
	ret=Play();
	//    
    /*
     if(ret==TRUE)
        {
            // 等待播放结束
            long evCode;
            m_pEvent->WaitForCompletion(INFINITE, &evCode);
		   //	Stop();
		   //  CleanUp();
	    	//	return;
        }
	*/
   //MSG  msg; 
	while(true)
	{		    
          // if  (::PeekMessage(&msg,NULL,0,0,PM_REMOVE))  
          // {  
          //             if  (msg.message==WM_QUIT)    
          //             {  
          //                         PostMessage(-1);  
		  //						   break;//
          //             }  
          //             ::TranslateMessage(&msg);  
           //            ::DispatchMessage(&msg);  
          // } 
		if(m_all_run_flag==false)	break;
		if(m_video_finished_flag==true) break;
         Sleep(100);
		if(m_all_run_flag==false)	break;
		if(m_video_finished_flag==true) break;
		

	}

   exit_video:  
	 //
		 CleanUp();		 
		  
		 return;

}

//=========================
/*
//FOR JPEG
HBITMAP CDemoDlg::LoadJpegImage(const CString &strFileName,int w,int h)
{
	FILE * pFile;		
	JSAMPARRAY pBuffer;	
	int nRowSize;	
	//
	struct jpeg_error_mgr jerr;
	struct jpeg_decompress_struct cinfo;

	
	if ((pFile = _wfopen(strFileName, _T("rb"))) == NULL) {
		//CString strError;
		//strError.Format(_T("Can't open file '%s'"), strFileName);
		//AfxMessageBox(strError);
		return 0;
	}
	
	cinfo.err = jpeg_std_error(&jerr);
	jpeg_create_decompress(&cinfo);
	jpeg_stdio_src(&cinfo, pFile);
	jpeg_read_header(&cinfo, TRUE);
	jpeg_start_decompress(&cinfo);

    ByteArray imageData(w*h*3);//cinfo.output_width* cinfo.output_height*3);		
	
	nRowSize = cinfo.output_width * cinfo.output_components;
	pBuffer = (*cinfo.mem->alloc_sarray)
		((j_common_ptr) &cinfo, JPOOL_IMAGE, nRowSize, 1);
	while (cinfo.output_scanline < cinfo.output_height)
	{
		jpeg_read_scanlines(&cinfo, pBuffer, 1);
		imageData.Append(pBuffer[0], nRowSize);

        //tmpdata=(BYTE *)::malloc(datalen+nRowSize);
		//if(tmpdata) return NULL;
		//memcpy(tmpdata,imageData,datalen);
		//memcpy(tmpdata+datalen,&pBuffer,nRowSize);
		//::free(imageData);
		//imageData=tmpdata;

	}

    
HBITMAP hBitmap = CSTScreenBuffer::CreateBitmapByRGBArray(imageData.GetData(), cinfo.output_width, cinfo.output_height);
    //CSTScreenBuffer m_st;
//HBITMAP hBitmap =m_st.CreateBitmapByRGBArray(imageData.GetData(), cinfo.output_width, cinfo.output_height);
  //if(imageData) ::free(imageData);
  //if(tmpdata)	::free(tmpdata);
 //if(!hBitmap) return NULL;
//	ASSERT(hBitmap);//???


	jpeg_finish_decompress(&cinfo);
	jpeg_destroy_decompress(&cinfo);
	fclose(pFile);

	return hBitmap;
}*/
//
//for gif
HBITMAP CDemoDlg::LoadGifCurFrame(BYTE *imageData,LPCGLOBAL_INFO gi,LPCFRAME fm)
{	
    //define color table    
       if(!imageData)  return NULL;
	  // 
	    //BYTE user_myrgb[3*256];
        //BYTE myrgb[3*256];
		//BYTE *imageData;
        BYTE *pColorTable;
		

	   if(fm->lFlag)//是局部调色板,   // 局部调色板入口数:fm->lSize;
	   {                 
         pColorTable=fm->pColorTable;                
	   }
	  else if(gi->gFlag) //全局调色板=有//色板入口数:gi->gSize;
	   {
         pColorTable=gi->gColorTable;          
	   } 
	  else// if(!gi->gFlag&&!fm->lFlag)////全局调色板=无,无局部调色板 :自定义调色板//???
	   {  	//自定义调色板
           pColorTable=user_myrgb;
       }
	  /*
    //全局调色板是否按优先排序gSort---DEBUG
	  if(gi->gSort)
	  {
		  int g,s;
		  g=0;
		  s=g;
	  }
	////局部调色板数据是否按优先排序sortFlag--DEBUG
	  if(fm->sortFlag)
	  {	   
		  int g,s;
		  g=0;
		  s=g;  
	  }*/
	 long pos1,pos2;
	 long x,y;

	 x=fm->imageLPos;
	 y=fm->imageTPos;
	 long w,h,H;

	// pos0=fm->imageTPos*fm->imageWidth+fm->imageLPos; 
	 //gi->scrWidth		 gi->scrHeight 
//    ByteArray imageData(gi->scrHeight* gi->scrHeight*3);
	//get data to buffer
	   /*处置方法(Disposal Method):
	   指出处置图形的方法,当值为:
                        0 - 不使用处置方法
                        1 - 不处置图形,把图形从当前位置移去
                        2 - 回复到背景色
                        3 - 回复到先前状态
                        4-7 - 自定义
						
	注意:
	1 - 不处置图形,把图形从当前位置移去 
    这一句有问题,为1时,应该是保留当前的图像,再绘制一帧图像在上面

	 */
    //不使用处置方法:0
//	BOOL disp_flag;
//	disp_flag=true;
	if(fm->ctrlExt.active)
	{
	 switch (fm->ctrlExt.disposalMethod)
	 {		
		case 1://不处置图形,把图形从当前位置移去--DEBUG
               {
               //int i,j;
	           //i=1;
	           //j=i;
			   // //disp_flag=false;
			   }
			   break;
		case 2://回复到背景色
			   	if(gi->gFlag)
				{			   
                 for( h=0;h<gi->scrHeight ;h++)
                  for( w=0;w<gi->scrWidth ;w++)
				  {  
                   //fm->dataBuf[h*fm->imageWidth+w]
			       //有透明色//图象扩展参数(与透明背景和动画有关)
				   pos1=(h*gi->scrWidth+w)*3+0;//
				  // pos1=(h*fm->imageWidth+w)*3+0;//
				   //gi->scrWidth 
				   pos2=gi->gColorTable[gi->BKColorIdx]*3+0;
				   //R 				   
				   imageData[pos1++]=pColorTable[pos2++];
				   //G
				   imageData[pos1++]=pColorTable[pos2++];				   
				   //B
				   imageData[pos1]=pColorTable[pos2];		   
				  }
				}
			   break;
		case 3://回复到先前状态
			   {
               //int i,j;
	           //i=3;
	           //j=i;
			   }
			   break;
		case 0://不使用处置方法
		default:
			   {
               //int i,j;
	           //i=0;
	           //j=i;
			   }
			   break;
	 } 
	}

	/////////////实际帧数据处理===============================	
  //  if(disp_flag)
	{
     if(fm->interlaceFlag)//数据是交错的
	   {//
            //long w,h,H;
             //T1[0,8,16,8*K]
             H=0;
             for( h=0;h<fm->imageHeight;h+=8,H++)
              for( w=0;w<fm->imageWidth;w++)
              {
                //fm->dataBuf[h*fm->imageWidth+w]
                //有透明色//图象扩展参数(与透明背景和动画有关)
               if(fm->ctrlExt.active&&fm->ctrlExt.trsFlag&&           
                  (UINT)(fm->dataBuf[H*fm->imageWidth+w])==(UINT)(fm->ctrlExt.trsColorIndex) 
				 )
               {
					   continue; 
			   }
			   else
               {   pos1=((h+y)*gi->scrWidth+w+x) *3 +0;			    
				   //pos1=(h*fm->imageWidth+w) *3 +0;
				   pos2=fm->dataBuf[H*fm->imageWidth+w]*3+0;
				   //R 				   
				   imageData[pos1++]=pColorTable[pos2++];
				   //G
				   imageData[pos1++]=pColorTable[pos2++];				   
				   //B
				   imageData[pos1++]=pColorTable[pos2++];
			   }	 
			  }
             //T2[4,12,20,4+8*K]
              for( h=4;h<fm->imageHeight;h+=8,H++)
              for( w=0;w<fm->imageWidth;w++)
              {
                //fm->dataBuf[h*fm->imageWidth+w]

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -