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

📄 demodlg.cpp

📁 客户端: 这是一个完整的基于Wince 4.1图形图象,网络通讯(C/S)模式下的商用程序源代码包.
💻 CPP
📖 第 1 页 / 共 5 页
字号:
// DemoDlg.cpp : implementation file
//

#include "stdafx.h"
#include "PPPClient.h"
#include "DemoDlg.h"

#include "PPPClientDlg.h"
//for gif ani
#include "STScreenBuffer.h"
#include "ByteArray.h"
/*
//for bmp
#include "DIBSectionLite.h"
//for jpeg
#include "STScreenBuffer.h"
#include "ByteArray.h"
extern "C" {

	#include ".\JpegLib\jpeglib.h"
}*/
//


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CPPPClientDlg *m_main_dlg;
extern bool m_show_demo_flag;//

extern bool m_all_run_flag;
extern CList<LOGFONT,LOGFONT&> m_all_logfont;
extern SYSTEM_PARAMETER m_system_para;

#define SAFE_RELEASE(x) { if (x) x->Release(); x = NULL; }
long GetFontSizeW(HDC hdc,LPCTSTR str,long len)
{
   SIZE size;
   GetTextExtentPoint32(hdc,str,len,&size);
  return(size.cx);
}
long GetFontSizeH(HDC hdc,LPCTSTR str,long len)
{
   SIZE size;
   GetTextExtentPoint32(hdc,str,len,&size);
  return(size.cy);
}
extern CString m_ini_pathname;
/////////////////////////////////////////////////////////////////////////////
// CDemoDlg dialog

CDemoDlg::CDemoDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CDemoDlg::IDD, pParent)
{
	m_pGraph = NULL;
	m_pMediaControl = NULL;
	m_pEvent = NULL;
	m_pMediaSeeking = NULL;
	pBV=NULL;
	//m_strMediaFile = "";
	m_isPlaying = FALSE;

	m_video_finished_flag=false;
    //
	m_brush .CreateSolidBrush (RGB ( 0, 0, 0 ) ) ;
	m_drag_flag=false;
	//{{AFX_DATA_INIT(CDemoDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CDemoDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDemoDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDemoDlg, CDialog)
	//{{AFX_MSG_MAP(CDemoDlg)
	ON_WM_PAINT()
	ON_WM_LBUTTONUP()
	ON_WM_DESTROY()
	ON_WM_MOVE()
	ON_WM_SIZE()
	ON_MESSAGE(WM_GRAPHNOTIFY, OnGraphNotify)
	ON_WM_SHOWWINDOW()
	ON_WM_SETCURSOR()
	ON_WM_CTLCOLOR()
	ON_WM_NCHITTEST()
	ON_WM_LBUTTONDOWN()
	ON_WM_MOUSEMOVE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()
//BEGIN_MESSAGE_MAP
// VCL_MESSAGE_HANDLER(WM_AUTORUN_MESSAGE,TMessage,OnAutoRunMessage);
// END_MESSAGE_MAP(TForm);
/////////////////////////////////////////////////////////////////////////////
// CDemoDlg message handlers

void CDemoDlg::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	if(m_isPlaying == FALSE)
	{
	
	//	CClientDC dc(GetDlgItem(IDC_VW_FRAME));
		dc.SetBkColor(RGB(0,0,0));
		CRect rc;//(0,0,320,240);
		//GetDlgItem(IDC_VW_FRAME)->
		GetClientRect(rc);
		//ClientToScreen(rc);
		dc.FillRect(rc, CBrush::FromHandle((HBRUSH)GetStockObject(BLACK_BRUSH)));
		// GetDlgItem(IDC_VW_FRAME)->Invalidate();
	
		
	}
	else
	{
		CDialog::OnPaint();
	}

	//CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here

	// Do not call CDialog::OnPaint() for painting messages
}

void CDemoDlg::OnLButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
//	m_drag_flag=false;

	::PostMessage(m_main_dlg->GetSafeHwnd(),WM_SHOW_MAINWND_MESSAGE,0,0); 
	CDialog::OnLButtonUp(nFlags, point);
}

BOOL CDemoDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	//自定义调色板 for gif
       for(int ii=0;ii<256;ii++)
        {
              user_myrgb[3*ii+0]=ii;
              user_myrgb[3*ii+1]=ii;
              user_myrgb[3*ii+2]=ii;
        }
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CDemoDlg::OnDestroy() 
{
	CDialog::OnDestroy();
	
	// TODO: Add your message handler code here
	CleanUp();
	m_brush.DeleteObject(); 
}

void CDemoDlg::ShowTextFile(CString filename,int in,int out,long speed,long delaytime,TEXTPROPERTY tp)
{  
//	TEXTPROPERTY
    FILE *fp1;
	fp1=fopen(filename,"rb");
	if(!fp1) return;

  LOGFONT lg,lf;
  
  memset(&lf, 0, sizeof(LOGFONT));       // Zero out the structure.
  POSITION pos=m_all_logfont.FindIndex( tp.m_text_font_name);
  if(pos)
  {
	  lg=m_all_logfont.GetAt(pos);	
	  lf=lg;
	  //lstrcpy(lf.lfFaceName, lg.lfFaceName);
	  lf.lfWidth=tp.m_text_font_width;
	  lf.lfHeight=tp.m_text_font_height;
	  
	  //fc,bc  

  }
  else
  {
   lf.lfHeight = 12;                      // Request a 16-pixel-height font.
   lf.lfWidth =16 ;
   lstrcpy(lf.lfFaceName, _T("Arial"));   // Request a face name "Arial".
  }
 
  CFont font;  
  //create font
  VERIFY(font.CreateFontIndirect(&lf));  // Create the font.
 
   CClientDC dc(this);
   CRect rect;
   GetClientRect(&rect);
   //rect.Width 
   DWORD  w,h;
   w=rect.Width();
   h=rect.Height(); 
   //create brush for fillrect by black color
   CBrush brush;
   brush.CreateSolidBrush(RGB(0,0,0));
   
   //
    CDC MemDC;
	CBitmap tmpbmp,*oldbmp;
  // CDC MemDC;
   MemDC.CreateCompatibleDC(&dc); 
  // CBitmap tmpbmp,*oldbmp;
   tmpbmp.CreateCompatibleBitmap(&dc,w,h);
   oldbmp=MemDC.SelectObject(&tmpbmp);    //

   //MemDC.SetBkMode(TRANSPARENT); 
   //cls
   MemDC.FillRect(CRect(0,0,w,h),&brush); 

   //select cur font
   CFont* def_font = MemDC.SelectObject(&font);
   //set text color
   //set bkcolor
   MemDC.SetTextColor(tp.m_text_fc_color);
   MemDC.SetBkColor(tp.m_text_bc_color);  
   //set text property
   //MemDC.m_hDC 
   
   // HDC hdc;                   // handle to device context 
    TEXTMETRIC tm;             // structure for text metrics  
    //hdc = ::GetDC(this->m_hWnd); 
    //GetTextMetrics(hdc, &tm); 
   ::GetTextMetrics(MemDC.m_hAttribDC,&tm);
	
	///
     
    // Save the average character width and height.  
	DWORD dwCharX;      // average width of characters 
    DWORD dwCharY;      // height of characters 
    dwCharX = tm.tmAveCharWidth; 
    dwCharY = tm.tmHeight; 
	///
    DWORD dwLineLen;    // line length 
    DWORD dwLines;      // text lines in client area 
	//
	dwLineLen = w - dwCharX; 
    dwLines = h / dwCharY; 
    
	//
	  //// Retrieve the character's width 
      // the character. 
    int nCharWidth = 0; // width of a character 

	
  //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
   char ch[3];
   DWORD X,Y;
   X=0;
   Y=0;
   FILE *fp;   
   fp=fopen(filename.GetBuffer(filename.GetLength()),"rb");
  // if(!fp)  goto exit_text;
   while(!feof(fp))
   {
	   if(m_all_run_flag==false) break;
	   //
	   if(fread((char *)&ch[0],1,sizeof(ch[0]),fp)!=sizeof(ch[0])) break;
	   //
	   //if( ferror( fp ) ) 
	   //{
		   //debug
		 //  int k,d;
		  // k=0;
		  // d=k;		   
	   //}
	   if((BYTE)ch[0]<0X80)//0x20
	   {
            
		 if(ch[0]<0x20)
		 {
		   if(ch[0]=='\n')
		   {
            //
			   X = 0; 
               ++Y; 
			   if(Y>=dwLines)
			   {
				Y=0;
			
				//draw cur full text pic
				//....
				DemoPic(dc,MemDC, w, h, in,out, speed,delaytime);
				//
				Sleep(delaytime);
				//cls
                 MemDC.FillRect(CRect(0,0,w,h),&brush); 
			   }
		   }
		   continue;            
		 }
		 else
		 {
			 //draw ansi text
			 // GetCharWidth32(MemDC.m_hAttribDC, ch[0], ch[0], &nCharWidth);
	         nCharWidth=GetFontSizeW(MemDC.m_hAttribDC, ch, 1);
	         if(X+nCharWidth>w)
			 {
              X=0;
			  ++Y;
		      if(Y>=dwLines)
			  {
		        Y=0;
		       //draw cur full text pic
		       //....
			   DemoPic(dc,MemDC, w, h, in,out, speed,delaytime);                
		      //delaytime
			   Sleep(delaytime);
			  //cls
              MemDC.FillRect(CRect(0,0,w,h),&brush); 			 
			  }
		     
            //		
			 }
	       //DRAW CHAR nCaretPosY * dwCharY
	        //MemDC.ExtTextOut(X, Y*dwCharY, ETO_OPAQUE, NULL, ch, 1,NULL);  
			MemDC.TextOutA(X, Y*dwCharY,ch,1);	   
	        X += nCharWidth;   
		 }
	   }
	   else
	   {
         if(fread((char *)&ch[1],1,sizeof(ch[1]),fp)!=sizeof(ch[1])) break;
         ch[2]='\0';
		 //draw H1,H2
          //GetCharWidth32(MemDC.m_hAttribDC, ch[0], ch[1], &nCharWidth);
	      nCharWidth=GetFontSizeW(MemDC.m_hAttribDC, ch, 2);
	     if(X+nCharWidth>w)
		 {
          X=0;
		  ++Y;
		  if(Y>=dwLines)
		  {
		   Y=0;		   
		   //draw cur full text pic
		   //....
			DemoPic(dc,MemDC, w, h, in,out, speed,delaytime);                
		   //delaytime
			Sleep(delaytime);
			//cls
            MemDC.FillRect(CRect(0,0,w,h),&brush); 			 
		  }
		  
         //		
		 }
	    //DRAW CHAR nCaretPosY * dwCharY
	    //MemDC.ExtTextOut(X, Y*dwCharY, ETO_OPAQUE, NULL, ch, 1,NULL);  	   
		 MemDC.TextOutA(X, Y*dwCharY,ch,2);
	     X += nCharWidth;   
	   }
	   //
	  // ch[1]='\0';//NULL;     

   }
  
   //the rest half screen text
   if(Y>0||X>0)
   {
    //draw cur full text pic
	DemoPic(dc,MemDC, w, h, in,out, speed,delaytime);
    //delaytime
	Sleep(delaytime);
   }
   /////////////////////////////////////////////////////// 
   //close file 
   fclose(fp); 
  //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
  
//exit_text:
   //....
	//delete brush
   brush.DeleteObject(); 
   //DemoPic(dc,MemDC, w, h, in,out, speed,delaytime);
   //::ReleaseDC(this->m_hWnd, hdc); 
   //release font
   MemDC.SelectObject(def_font);
   //Finished with the font, now delete the font object.
   font.DeleteObject();
   
   //releasse dc and bitmap
   MemDC.SelectObject(oldbmp);
   tmpbmp.DeleteObject();
   MemDC.DeleteDC();

}
void CDemoDlg::ShowPicture(CString filename,int in,int out,long speed,long delaytime,int position)
{
	if(filename.IsEmpty()) return; 
    FILE *fp;
	fp=fopen(filename.GetBuffer(filename.GetLength()),"rb");
	if(!fp) return;
	fclose(fp);
	//
	CPicture m_picture;
	if(m_picture.Load(filename)==false) return;
	CClientDC dc(this);
	CRect rect;
	GetClientRect(&rect);
	int w,h;
	w=rect.Width();
	h=rect.Height(); 

	//
	   
    	CBitmap tmpbmp,*oldbmp;
	    CDC MemDC;		  
		//######################################################################
		MemDC.CreateCompatibleDC(&dc);          
        tmpbmp.CreateCompatibleBitmap(&dc,w,h);
        oldbmp=MemDC.SelectObject(&tmpbmp); 
        //copy...		
		//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$	
		long pw,ph;
		pw=m_picture.GetWidth(dc.GetSafeHdc( ));
		ph=m_picture.GetHeight(dc.GetSafeHdc( ));
		if(position==0)//center
		{
         long sx,sy;
		 if(pw>=w) 
			 sx=0;
		 else
			 sx=(w-pw)/2;
		 ///////////////////
		 if(ph>=h) 
			 sy=0;
		 else
			 sy=(h-ph)/2;
		 //
         if(m_picture.Draw(&MemDC,sx,sy,pw,ph)==false)
		  {
			MemDC.SelectObject(oldbmp); 
            tmpbmp.DeleteObject(); 
            MemDC.DeleteDC(); 
			return;
		  }
		}
		else if(position==1)//stretch
		{
          if(m_picture.Draw(&MemDC,0,0,w,h)==false)
		  {
			MemDC.SelectObject(oldbmp); 
            tmpbmp.DeleteObject(); 
            MemDC.DeleteDC(); 
			return;
		  }
		}
		else//flat--对视频无效
		{
         
		 CBitmap tb,*ob;
	     CDC mdc;		  
		//######################################################################
		mdc.CreateCompatibleDC(&dc);          
        tb.CreateCompatibleBitmap(&dc,pw,ph);
        ob=mdc.SelectObject(&tb); 
		//

⌨️ 快捷键说明

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