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

📄 gtmpegwnd.cpp

📁 一个完整的数字硬盘录像机系统软件
💻 CPP
📖 第 1 页 / 共 5 页
字号:
					 }
					 else
					    m_nPlays++;
				}
				return;
			  }

		   }
		      break;
	   case 2:
		   {
		      CDayPlayDlg dlg(this);
			  if(dlg.DoModal()==IDOK)
			  {
	            CVideoPos* pWnd=(CVideoPos*)GetDlgItem(IDC_VIDEO_POS+dlg.m_nChannel);
	            g_pDevice[dlg.m_nChannel]->StopDisplay();
	            if(!g_pDevice[dlg.m_nChannel]->StartPlayback())
				{
	                CVideoPos* pWnd=(CVideoPos*)GetDlgItem(IDC_VIDEO_POS+dlg.m_nChannel);
		            g_pDevice[dlg.m_nChannel]->StartDisplay();
				}
				else
				{
					     if(m_nPlays<=0)
						 {
						    m_nPlays=1;
				            //AfxBeginThread((AFX_THREADPROC) CheckPlay,this);
						 }
						 else
						    m_nPlays++;
				}
				return;
			  }

		   }
		      break;
	}
}
////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////
void CGtMpegWnd::DisplayAll()
{
	for(DWORD i=0;i<g_dwNumberOfSlots;i++)
	{
        if((int)i<m_nPicNumX*m_nPicNumY)
			g_pDevice[i]->StartDisplay();
	}
}
////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////
void CGtMpegWnd::StopDisplayAll()
{
	for(DWORD i=0;i<g_dwNumberOfSlots;i++)
	{
		g_pDevice[i]->StopDisplay();
	}
}
////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////
void  CGtMpegWnd::PauseDisplay()
{
	if(!m_bStart)
		return;
	for(DWORD i=0;i<g_dwNumberOfSlots;i++)
       g_pDevice[i]->PauseDisplay();
}
////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////
void  CGtMpegWnd::RestoreDisplay(int nFrame)
{
	if(!m_bStart)
		return;
	for(DWORD i=0;i<g_dwNumberOfSlots;i++)
      g_pDevice[i]->RestoryDisplay(nFrame);
}
////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////
void CGtMpegWnd::OnRecord() 
{
	for(DWORD i=0;i<g_dwNumberOfSlots;i++)
	{
		if(m_nChannel[i]==1)
		{
		  if(!g_pDevice[i]->m_bRecord)
		  {
			if(g_pDevice[i]->StartRecord())
			{
				if(m_nRecords<=0)
				{
				   m_nRecords=1;
				   //AfxBeginThread((AFX_THREADPROC) CheckRecord,this);
				}
				else
				  m_nRecords++;
			}
		  }
		}
	 }
}
////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////
void CGtMpegWnd::OnStop() 
{
	for(DWORD i=0;i<g_dwNumberOfSlots;i++)
	{
	   	if(m_nChannel[i]==1)
		{
		    if(g_pDevice[i]->m_bRePlay)
			{
			   if(m_nPlays>0)
			       m_nPlays--;
			   g_pDevice[i]->StopPlayback();
			   g_pDevice[i]->StartDisplay();
			}
			else if(g_pDevice[i]->m_bRecord)
			{
				if(m_bAlarming)
				  m_AlarmSound.Pause();
				m_nRecords--;
				g_pDevice[i]->StopRecord();
				g_pDevice[i]->StartDisplay();
				if(m_bAlarming)
				  m_AlarmSound.Play();
				if(theApp.m_bAlarm)
				{
                   m_wndAlarm[i].SetSway(FALSE);
				   StopChannelZone(i);
				}
			}
			else 
               g_pDevice[i]->StopDisplay();
		}
	}
}
//////////////////////////////////////
//
//////////////////////////////////////
BOOL CGtMpegWnd::OpenComm()
{
    CString sCom;
	sCom.Format("COM%d",AfxGetApp()->GetProfileInt("系统参数","串口",2));
	int     nRate=theApp.GetProfileInt("通讯参数","波特率",CBR_9600);;
    int     nDataBits=    theApp.GetProfileInt("通讯参数","数据位",8);
	int     nParity=theApp.GetProfileInt("通讯参数","奇偶校验",0);
	int     nStopBits=ONESTOPBIT;
	CString sStopBits=theApp.GetProfileString("通讯参数","停止位","1");
	if(sStopBits=="1.5")
	   nStopBits=ONE5STOPBITS;
	else if(sStopBits=="2")
	   nStopBits=TWOSTOPBITS;
    m_OSRead.Offset =0;
    m_OSRead.OffsetHigh=0 ;
    m_OSWrite.Offset = 0 ;
    m_OSWrite.OffsetHigh = 0 ;
	m_OSRead.hEvent=CreateEvent(NULL,TRUE,FALSE,NULL);
	if(m_OSRead.hEvent==NULL)
	{
		return FALSE;
	}
	m_OSWrite.hEvent=CreateEvent(NULL,TRUE,FALSE,NULL);
	if(m_OSWrite.hEvent==NULL)
	{
		return FALSE;
	}	
   	m_hCom=CreateFile(sCom,GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL|FILE_FLAG_OVERLAPPED,NULL);
	if(m_hCom==NULL)
	{
		return FALSE;
	}
    COMMTIMEOUTS  CommTimeOuts ;
    CommTimeOuts.ReadIntervalTimeout=0xFFFFFFFF;
    CommTimeOuts.ReadTotalTimeoutMultiplier=0;
    CommTimeOuts.ReadTotalTimeoutConstant=1000;
    CommTimeOuts.WriteTotalTimeoutMultiplier=2*nRate/nRate;
    CommTimeOuts.WriteTotalTimeoutConstant=0;
    SetCommTimeouts(m_hCom, &CommTimeOuts ) ;
	DWORD dwCommEvents=EV_RXFLAG|EV_RXCHAR;
    SetCommMask(m_hCom,dwCommEvents);
	//获得串口设置
    m_CommDCB.DCBlength = sizeof( DCB ) ;
	GetCommState(m_hCom,&m_CommDCB);
    //设置串口
    m_CommDCB.BaudRate =nRate;
    m_CommDCB.ByteSize = nDataBits;
    m_CommDCB.Parity =nParity;
    m_CommDCB.StopBits =nStopBits;
    /////////////////////////////////////////////////////////////////////
    m_CommDCB.fOutxDsrFlow =FALSE;
    m_CommDCB.fDtrControl = DTR_CONTROL_ENABLE ;
	m_CommDCB.fOutxCtsFlow =FALSE;
    m_CommDCB.fRtsControl = RTS_CONTROL_DISABLE;
	m_CommDCB.XonChar = ASCII_XON ;
    m_CommDCB.XoffChar = ASCII_XOFF ;
    m_CommDCB.XonLim = 100 ;
    m_CommDCB.XoffLim = 100 ;
    m_CommDCB.fBinary = TRUE ;
    m_CommDCB.fParity = TRUE ;
	//m_CommDCB.EvtChar = 0x06 ;
	//m_CommDCB.EofChar = 0x14 ;
    //////////////////////////////////////////////////////////////////// 
    PurgeComm(m_hCom, PURGE_TXABORT|PURGE_RXABORT|PURGE_TXCLEAR|PURGE_RXCLEAR ) ;
	SetCommState(m_hCom,&m_CommDCB); 
    EscapeCommFunction(m_hCom,SETDTR) ;
	return TRUE;
}
////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////
void CGtMpegWnd::CloseComm()
{
  	if(m_hCom!=NULL)
	{
       m_bComWorking=FALSE;
	   SetCommMask(m_hCom,0);
       EscapeCommFunction(m_hCom,CLRDTR);
       PurgeComm(m_hCom, PURGE_TXABORT |PURGE_RXABORT|PURGE_TXCLEAR | PURGE_RXCLEAR ) ;
	   CloseHandle(m_hCom);
	   m_hCom=NULL;
	}
}
///////////////////////////////////////////
//
////////////////////////////////////////////
void CGtMpegWnd::OnPicPlane1() 
{
   m_nPicNumX=1;
   m_nPicNumY=1;
   StopDisplayAll();
   int nChannel=0;
   for(DWORD i=0;i<g_dwNumberOfSlots;i++)
   {
       if(m_nChannel[i]==1)
	   {
			nChannel=i;
			break;
	   }
   }
   AdjustMpegWindow(nChannel);
   if(g_pDevice[nChannel]->m_bRePlay)
      g_pDevice[nChannel]->PlaybackAdjust();
   else
      g_pDevice[nChannel]->StartDisplay();
}
///////////////////////////////////////////
//
////////////////////////////////////////////
void CGtMpegWnd::ArrangeFourMpegWnd(int arChannel[4])
{
	m_DisplaySize.cx=(m_rMpegRect.Width()-2*20-(m_nPicNumX-1)*3)/m_nPicNumX;
    m_DisplaySize.cy=(m_rMpegRect.Height()-2*20-m_nPicNumY*_SHOW_WIDTH)/m_nPicNumY;
    //
	CRect rPicRect,rTempRect;
	int nStartX=m_rMpegRect.left+20,nStartY=m_rMpegRect.top+20;
	for(int k=0;k<9;k++)
	{
	   GetDlgItem(IDC_VIDEO_POS+k)->ShowWindow(SW_HIDE);
	   GetDlgItem(IDC_CHANNEL_SHOW0+k)->ShowWindow(SW_HIDE);
	}
	for(int i=0;i<m_nPicNumX;i++)
	{
	   for(int j=0;j<m_nPicNumY;j++)
	   {
		   GetDlgItem(IDC_VIDEO_POS+arChannel[i*m_nPicNumY+j])->GetWindowRect(rPicRect);
		   ScreenToClient(rPicRect);
		   rPicRect.left=nStartX;
		   rPicRect.top=nStartY;
		   rPicRect.right=rPicRect.left+m_DisplaySize.cx;
		   rPicRect.bottom=rPicRect.top+m_DisplaySize.cy;
		   ClientToScreen(rPicRect);
		   GetDlgItem(IDC_VIDEO_POS+arChannel[i*m_nPicNumY+j])->MoveWindow(rPicRect);
		   GetDlgItem(IDC_VIDEO_POS+arChannel[i*m_nPicNumY+j])->Invalidate();
		   int nPosX=rPicRect.left;
		   int nPosY=rPicRect.bottom;
		   int nWidth=rPicRect.Width();
		   GetDlgItem(IDC_CHANNEL_SHOW0+arChannel[i*m_nPicNumY+j])->GetWindowRect(rTempRect);
		   ScreenToClient(rTempRect);
		   rTempRect.left=nPosX;
		   rTempRect.top=nPosY;
		   rTempRect.right=rTempRect.left+nWidth;
		   rTempRect.bottom=rTempRect.top+_SHOW_WIDTH;
		   GetDlgItem(IDC_CHANNEL_SHOW0+arChannel[i*m_nPicNumY+j])->MoveWindow(rTempRect);
		   GetDlgItem(IDC_VIDEO_POS+arChannel[i*m_nPicNumY+j])->ShowWindow(SW_SHOW);
           GetDlgItem(IDC_VIDEO_POS+arChannel[i*m_nPicNumY+j])->Invalidate();
		   GetDlgItem(IDC_CHANNEL_SHOW0+arChannel[i*m_nPicNumY+j])->ShowWindow(SW_SHOW);
		   nStartX+=m_DisplaySize.cx+3;  
	   }
	   nStartX=m_rMpegRect.left+20;
	   nStartY+=m_DisplaySize.cy+_SHOW_WIDTH;
	}
}
///////////////////////////////////////////
//
////////////////////////////////////////////
void CGtMpegWnd::OnPicPlane4() 
{
   int    narChannel[4];
   m_nPicNumX=2;
   m_nPicNumY=2;
   narChannel[0]=0; 
   narChannel[1]=1; 
   narChannel[2]=2; 
   narChannel[3]=3;
   StopDisplayAll();
   int nSort=-1;
   for(DWORD j=0;j<g_dwNumberOfSlots;j++)
   {
       if(m_nChannel[j]==1)
	   {
		 nSort++;
		 narChannel[nSort]=j;
	   }
   }
   if(nSort!=3)
   {
       narChannel[0]=0; 
       narChannel[1]=1; 
       narChannel[2]=2; 
       narChannel[3]=3;
   }
   ArrangeFourMpegWnd(narChannel);
   for(int i=0;i<4;i++)
   {
      if(g_pDevice[narChannel[i]]->m_bRePlay)
         g_pDevice[narChannel[i]]->PlaybackAdjust();
      else
         g_pDevice[narChannel[i]]->StartDisplay();
   }
}
///////////////////////////////////////////
//
////////////////////////////////////////////
void CGtMpegWnd::OnPicPlane9() 
{
   if(m_nPicNumX==3&&m_nPicNumY==3)
	   return;
   m_nPicNumX=3;
   m_nPicNumY=3;
   StopDisplayAll();
   AdjustMpegWindow();
   for(int i=0;i<theApp.m_nChannels;i++)
   {
     if(g_pDevice[i]->m_bRePlay)
        g_pDevice[i]->PlaybackAdjust();
     else
        g_pDevice[i]->StartDisplay();
   }
}
///////////////////////////////////////////
//
////////////////////////////////////////////
BOOL CGtMpegWnd::PreTranslateMessage(MSG* pMsg) 
{
	if(m_bStart)
	{
		if(GetActiveWindow( )!=this)
			PauseDisplay();
		else
		   RestoreDisplay();
	}
	if (pMsg->message == WM_NCLBUTTONDBLCLK)
			return TRUE;
	if (pMsg->message ==WM_SYSKEYDOWN || pMsg->message == WM_KEYFIRST)
	{
		int nChar=pMsg->wParam;
		if(nChar==27||nChar==18||nChar==115||nChar==13)//屏蔽[ESC]键与[ALT+F4]键
		{
		  return TRUE;
		}
		if(nChar==35)
		{
		  m_nRecords=0;
		  theApp.m_bShutDown=FALSE;
          FreeObject();
		  CDialog::OnOK();
		  return TRUE;
		}
		if(nChar>=49&&nChar<=56)
		{
			if(m_bCompressCard)
			{
			  UINT nChar1=nChar-49;
			  if(nChar1>=0&&nChar1<=7)
			  {
				 for(DWORD i=0;i<g_dwNumberOfSlots;i++)
                   g_pDevice[i]->StopCheck();
				 if(!g_pDevice[nChar1]->m_bRecord)
				   g_pDevice[nChar1]->StartLVPT();
			  }
			}
		}
		else if(nChar==48)
		{
			 for(DWORD i=0;i<g_dwNumberOfSlots;i++)
                g_pDevice[i]->StopCheck();
		}
	}
	return CDialog::PreTranslateMessage(pMsg);
}
///////////////////////////////////////////////
//
////////////////////////////////////////////////
void CGtMpegWnd::ForceStopRecord(CString sRoot)
{
   for(DWORD k=0;k<g_dwNumberOfSlots;k++)
   {
	   if(g_pDevice[k]->m_bRecord)
	   {
		   if(g_pDevice[k]->m_sRecordRootPath==sRoot)
		   {
			 m_nRecords--;
		     g_pDevice[k]->StopRecord();
			 g_pDevice[k]->StartDisplay();
			 CString sMsg;
			 sMsg.Format("磁盘空间不足,系统强制停止%02d路的录像");
			 m_cMsgListBox.AddString(sMsg);
			 sndPlaySound(GetAppPath()+"Sound\\停止录像.wav",SND_SYNC);
		     sndPlaySound(GetAppPath()+"Sound\\停止录像.wav",SND_SYNC);
		   }
	   }
   }
}
///////////////////////////////
//
///////////////////////////////
void CGtMpegWnd::OnBackup() 
{
     CVideoBackupDlg dlg(this);
	 dlg.DoModal();
}
///////////////////////////////
//
///////////////////////////////
void CGtMpegWnd::OnLButtonDblClk(UINT nFlags, CPoint point) 
{
	if(theApp.m_bRecord)
	{
		CRect rect;
		m_cLogo.GetWindowRect(rect);
		if(rect.PtInRect(point))
		{
		  if(!m_bCompressCard)
		  {
			 m_bCompressCard=TRUE;
			 delete m_pLogoObject;
			 m_pLogoObject=NULL;
			 InvalidateRect(rect);
		  }

⌨️ 快捷键说明

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