12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097 |
- // LocalFilePlay.cpp : implementation file
- //
- #include "stdafx.h"
- #include "newclient.h"
- #include "LocalFilePlay.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CLocalFilePlay dialog
- #define TIMER_INTERVAL 500
- #define USED_PORT 99
- extern SERVER_INFO serverinfo[MAXIPNUMBER];
- extern CLIENTPARAM ClientParam;
- BOOL g_bCapPic=FALSE;
- //完成文件索引回调函数
- void CALLBACK FileRefDone(DWORD nReserved,DWORD nUser)
- {
- CLocalFilePlay* pOwner=(CLocalFilePlay*)nUser;
- pOwner->F_UpdateStepBackUI(TRUE);
- }
- //抓图回调函数
- void CALLBACK DisplayCBFun(long nPort,char * pBuf,long nSize,long nWidth,long nHeight,long nStamp,long nType,long nReceaved)
- {
- if(!g_bCapPic)
- return;
- //转换函数,比较耗时,如果不想保存图片,请不要调用;
- CString csDir;
- CString csFile;
- CTime time=CTime::GetCurrentTime();
- csDir.Format("%s",ClientParam.m_csPictureSavePath);
- csFile.Format("%s\\Picture_%s_%02d_%4d%02d%02d_%02d%02d%02d_%d.bmp",csDir,CLocalFilePlay::m_csIP,CLocalFilePlay::iSelChannel, \
- time.GetYear(), time.GetMonth(), time.GetDay(), time.GetHour(), time.GetMinute(), time.GetSecond(), GetTickCount());
- if(!PlayM4_ConvertToBmpFile(pBuf,nSize,nWidth,nHeight,nType,csFile.GetBuffer(csFile.GetLength())))
- {
- TRACE("Convert to Bmp failed!");
- }
- g_bCapPic=FALSE;
- }
- CString CLocalFilePlay:: m_csIP="";
- int CLocalFilePlay::iSelChannel = -1;
- CLocalFilePlay::CLocalFilePlay(CWnd* pParent /*=NULL*/)
- : CDialog(CLocalFilePlay::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CLocalFilePlay)
- m_ctTimeStart = 0;
- m_ctTimeStop = 0;
- m_iChannelSel = -1;
- m_ctDateStart = 0;
- m_ctDateStop = 0;
- //}}AFX_DATA_INIT
- m_hPlayEnableIcon = AfxGetApp()->LoadIcon(IDI_PLAY_ENABLE);
- m_hPlayDisableIcon = AfxGetApp()->LoadIcon(IDI_PLAY_DISABLE);
- m_hPauseEnableIcon = AfxGetApp()->LoadIcon(IDI_PAUSE_ENABLE);
- m_hPauseDisableIcon = AfxGetApp()->LoadIcon(IDI_PAUSE_DISABLE);
- m_hStopEnableIcon = AfxGetApp()->LoadIcon(IDI_STOP_ENABLE);
- m_hStopDisableIcon = AfxGetApp()->LoadIcon(IDI_STOP_DISABLE);
- m_hSoundStartIcon= AfxGetApp()->LoadIcon(IDI_SOUND_ENABLE);
- m_hSoundStopIcon= AfxGetApp()->LoadIcon(IDI_SOUND_DISABLE);
- m_hGotoHeadDisableIcon = AfxGetApp()->LoadIcon(IDI_GOTOSTART_DISABLE);
- m_hGotoTailDisableIcon = AfxGetApp()->LoadIcon(IDI_GOTOEND_DISABLE);
- m_hFastDisableIcon = AfxGetApp()->LoadIcon(IDI_FASTFORWARD_DISABLE);
- m_hSlowDisableIcon= AfxGetApp()->LoadIcon(IDI_FASTBACKWARD_DISABLE);
- m_hGotoHeadEnableIcon = AfxGetApp()->LoadIcon(IDI_GOTOSTART_ENABLE);
- m_hGotoTailEnableIcon = AfxGetApp()->LoadIcon(IDI_GOTOEND_ENABLE);
- m_hFastEnableIcon = AfxGetApp()->LoadIcon(IDI_FASTFORWARD_ENABLE);
- m_hSlowEnableIcon = AfxGetApp()->LoadIcon(IDI_FASTBACKWARD_ENABLE);
- m_hStepEnableIcon= AfxGetApp()->LoadIcon(IDI_STEP_ENABLE);
- m_hStepDisableIcon = AfxGetApp()->LoadIcon(IDI_STEP_DISABLE);
- m_hStepBackEnableIcon = AfxGetApp()->LoadIcon(IDI_STEPBACK_ENABLE);
- m_hStepBackDisableIcon = AfxGetApp()->LoadIcon(IDI_STEPBACK_DISABLE);
- m_hCaptureIcon = AfxGetApp()->LoadIcon(IDI_PIC);
- }
- void CLocalFilePlay::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CLocalFilePlay)
- DDX_Control(pDX, IDC_LOCALFILRLIST, m_locFileList);
- DDX_Control(pDX, IDC_PROGRESS_SLIDER, m_ctlProgress);
- DDX_Control(pDX, IDC_VOLUME_SLIDER, m_ctlVolume);
- DDX_Control(pDX, IDC_COMBOSERVER, m_ServerCtrl);
- DDX_Control(pDX, IDC_COMBOCHANNEL, m_ChannelCtrl);
- DDX_Control(pDX, IDC_COMBOFILETYPE, m_FileTypeCtrl);
- DDX_DateTimeCtrl(pDX, IDC_TIMESTART, m_ctTimeStart);
- DDX_DateTimeCtrl(pDX, IDC_TIMESTOP, m_ctTimeStop);
- DDX_CBIndex(pDX, IDC_COMBOCHANNEL, m_iChannelSel);
- DDX_DateTimeCtrl(pDX, IDC_DATESTART, m_ctDateStart);
- DDX_DateTimeCtrl(pDX, IDC_DATESTOP, m_ctDateStop);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CLocalFilePlay, CDialog)
- //{{AFX_MSG_MAP(CLocalFilePlay)
- ON_BN_CLICKED(IDC_SEARCHLOCALLIST, OnSearch)
- ON_BN_CLICKED(IDC_DELETE, OnDelete)
- ON_BN_CLICKED(IDC_DELETEALL, OnDeleteall)
- ON_BN_CLICKED(IDC_PLAY_FILE, OnPlayFile)
- ON_BN_CLICKED(IDC_STOP, OnStop)
- ON_BN_CLICKED(IDC_SLOW, OnSlow)
- ON_BN_CLICKED(IDC_FAST, OnFast)
- ON_BN_CLICKED(IDC_CAPPIC, OnCappic)
- ON_BN_CLICKED(IDC_STEPBACK, OnStepback)
- ON_BN_CLICKED(IDC_STEP, OnStep)
- ON_BN_CLICKED(IDC_SOUND, OnSound)
- ON_WM_DESTROY()
- ON_WM_HSCROLL()
- ON_WM_LBUTTONDBLCLK()
- ON_WM_PAINT()
- ON_WM_TIMER()
- ON_CBN_SELCHANGE(IDC_COMBOSERVER, OnSelchangeComboserver)
- ON_CBN_SELCHANGE(IDC_COMBOFILETYPE, OnSelchangeCombofiletype)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CLocalFilePlay message handlers
- void CLocalFilePlay::SetParentWnd(HWND *hhWnd, int iParentNum)
- {
- VERIFY(iParentNum==2);
- m_hPareDlgWnd=hhWnd[0];
- m_hPareTabWnd=hhWnd[1];
- }
- BOOL CLocalFilePlay::OnInitDialog()
- {
- CDialog::OnInitDialog();
-
- // TODO: Add extra initialization here
- CRect rc(0, 0, 0, 0);
- GetParent()->GetClientRect(&rc);
- ((CTabCtrl*)GetParent())->AdjustRect(FALSE, &rc);
- MoveWindow(&rc);
- m_locFileList.InsertColumn(0,"文件名称",LVCFMT_LEFT,120,-1);
- m_locFileList.InsertColumn(1,"通道",LVCFMT_LEFT,40,-1);
- m_locFileList.InsertColumn(2,"类型",LVCFMT_LEFT,40,-1);
- m_locFileList.InsertColumn(3,"开始时间",LVCFMT_LEFT,120,-1);
- m_locFileList.InsertColumn(4,"结束时间",LVCFMT_LEFT,120,-1);
- m_ServerCtrl.AddString("请选择DVR");
- for(int i = 0; i < MAXIPNUMBER; i++)
- {
- if(serverinfo[i].m_csServerName != "")
- m_ServerCtrl.AddString(serverinfo[i].m_csServerName);
- }
-
- m_bPlay=FALSE;
- m_bPause=FALSE;
- m_bSound=FALSE;
- m_iTotalSeconds=0;
- m_bStep=FALSE;
- m_bFileRefCreated=FALSE;
- m_hPlayWnd = GetDlgItem(IDC_WND)->m_hWnd;
- m_bFullScreen=FALSE;
- m_hPareDlgWnd=NULL;
- m_hPareTabWnd=NULL;
- m_iChannelnumber = 16;
- F_InitUI();
- GetDlgItem(IDC_WND)->GetWindowRect(m_rcWnd);
- ScreenToClient(m_rcWnd);
- ShowWindow(SW_SHOW);
- CTime time1 = CTime::GetCurrentTime();
- CTime time(time1.GetYear(),time1.GetMonth(),time1.GetDay(),0,0,0);
- CTime time0(time1.GetYear(),time1.GetMonth(),time1.GetDay(),23,59,59);
- m_ctDateStart = time;
- m_ctTimeStart = time;
- m_ctDateStop = time1;
- m_ctTimeStop = time0;
- UpdateData(FALSE);
- m_ServerCtrl.SetCurSel(0);
- m_ChannelCtrl.SetCurSel(0);
- m_FileTypeCtrl.SetCurSel(0);
-
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- void CLocalFilePlay::OnSearch()
- {
- // TODO: Add your control notification handler code here
- UpdateData(TRUE);
- int iServerSel;
- CString csIP;
- CTime tStartTime,tStopTime;
- int iSum = 0;
- int m_iType;
- int i,j;
- if(!F_CheckDate(m_ctDateStart,m_ctDateStop))
- return;
- m_locFileList.DeleteAllItems();
- m_iTSum = 0;
- if(m_ServerCtrl.GetCurSel() == 0)
- {
- AfxMessageBox("请选择DVR!");
- return;
- }
- iServerSel = m_ServerCtrl.GetCurSel()-1;
- csIP.Format("%s",serverinfo[iServerSel].m_csServerIP);
-
- tStartTime = CTime(m_ctDateStart.GetYear(),m_ctDateStart.GetMonth(),m_ctDateStart.GetDay(),m_ctTimeStart.GetHour(),m_ctTimeStart.GetMinute(),m_ctTimeStart.GetSecond());
- tStopTime = CTime(m_ctDateStop.GetYear(),m_ctDateStop.GetMonth(),m_ctDateStop.GetDay(),m_ctTimeStop.GetHour(),m_ctTimeStop.GetMinute(),m_ctTimeStop.GetSecond());
- m_iType = m_FileTypeCtrl.GetCurSel();
- if(m_iChannelSel == 0)
- {
- //all channel
- for(i=0; i<=m_iChannelnumber; i++)
- {
- if(m_iType!=0)
- iSum = iSum + F_ShowlocalFile(csIP,m_iType,i+m_lStartChan, tStartTime, tStopTime);
- else
- {
- for(j = 1;j<=3;j++)
- iSum = iSum + F_ShowlocalFile(csIP,j,i+m_lStartChan, tStartTime, tStopTime);
- }
- }
- }
- else
- {
- if(m_iType!=0)
- iSum = F_ShowlocalFile(csIP,m_iType,m_iChannelSel-1+m_lStartChan, tStartTime, tStopTime);
- else
- {
- for(j = 1;j<=3;j++)
- iSum = iSum + F_ShowlocalFile(csIP,j,m_iChannelSel-1+m_lStartChan, tStartTime, tStopTime);
- }
- }
- if(iSum > 0)
- F_SetStopState();
- else
- F_InitUI();
- TRACE("共找到%d个文件",iSum);
- AfxMessageBox("文件查找结束!");
- UpdateData(FALSE);
- }
- void CLocalFilePlay::OnDelete()
- {
- // TODO: Add your control notification handler code here
- UpdateData(TRUE);
-
- int fileselpos = 0;
- CString csFileName;
- POSITION pos = m_locFileList.GetFirstSelectedItemPosition();
- if(pos == NULL)
- return;
- fileselpos = m_locFileList.GetNextSelectedItem(pos);
- TRACE("fileselpos = %d", fileselpos);
- csFileName=m_locFileList.GetItemText(fileselpos,0);
- if(csFileName.GetLength()==0)
- return;
- TRACE("Delete Mp4 filename = %s", csFileName);
- if(IDOK!=MessageBox("确定删除此文件吗?","警告",IDOK))
- return;
- if(DeleteFile(csFileName))
- {
- m_locFileList.DeleteItem(fileselpos);
- }
- else
- {
- CString csError;
- csError.Format("不能删除文件:%s!",csFileName);
- MessageBox(csError);
- }
- }
- void CLocalFilePlay::OnDeleteall()
- {
- // TODO: Add your control notification handler code here
- int iCount, i;
- CString csFileName;
-
- iCount = m_locFileList.GetItemCount();
- TRACE("iCount = %d", iCount);
- if(iCount < 1)
- return;
- if(IDOK!=MessageBox("确定删除所有文件吗?","警告",IDOK))
- return;
- for(i = iCount; i > 0; i--)
- {
- csFileName = m_locFileList.GetItemText(i-1, 0);
- if(csFileName.GetLength() == 0)
- continue;
- if(DeleteFile(csFileName))
- {
- m_locFileList.DeleteItem(i-1);
- }
- else
- {
- CString csError;
- csError.Format("不能删除文件:%s!",csFileName);
- MessageBox(csError);
- }
- }
- }
- void CLocalFilePlay::OnPlayFile()
- {
- // TODO: Add your control notification handler code here
- if(m_bPlay)
- {
- if(m_bStep)
- {
- PlayM4_Play(USED_PORT,m_hPlayWnd);
- F_SetPlayState();
- m_bStep=FALSE;
- }
- else
- F_Pause();
- return;
- }
- F_Play();
- if(m_bPlay)
- {
- F_SetPlayState();
- F_Sound(TRUE);
- SetTimer(PLAY_TIMER,TIMER_INTERVAL,NULL);
- }
- }
- void CLocalFilePlay::OnStop()
- {
- // TODO: Add your control notification handler code here
- if(!m_bPlay)
- return;
- m_ctlProgress.SetPos(0);
- CString csText;
- GetDlgItem(IDC_PLAYSTATUS)->SetWindowText(csText);
- KillTimer(PLAY_TIMER);
- csText.Format("%d/%d %02d:%02d:%02d/%02d:%02d:%02d",0,0,0,0,0,0,0,0);
- UpdateData(FALSE);
- Invalidate(TRUE);
- F_Stop();
- }
- void CLocalFilePlay::OnSlow()
- {
- // TODO: Add your control notification handler code here
- PlayM4_Slow(USED_PORT);
- }
- void CLocalFilePlay::OnFast()
- {
- // TODO: Add your control notification handler code here
- PlayM4_Fast(USED_PORT);
- }
- void CLocalFilePlay::OnCappic()
- {
- // TODO: Add your control notification handler code here
- g_bCapPic=TRUE;
- }
- void CLocalFilePlay::OnStepback()
- {
- // TODO: Add your control notification handler code here
- if(m_bPause)
- F_Pause();
- PlayM4_OneByOneBack(USED_PORT);
- m_bStep=TRUE;
- F_SetPauseState();
- }
- void CLocalFilePlay::OnStep()
- {
- // TODO: Add your control notification handler code here
- if(m_bPause)
- F_Pause();
- PlayM4_OneByOne(USED_PORT);
- m_bStep=TRUE;
- F_SetPauseState();
- }
- void CLocalFilePlay::OnSound()
- {
- // TODO: Add your control notification handler code here
- F_Sound(!m_bSound);
- }
- void CLocalFilePlay::OnDestroy()
- {
- F_Stop();
- CDialog::OnDestroy();
-
- // TODO: Add your message handler code here
-
- }
- void CLocalFilePlay::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
- {
- // TODO: Add your message handler code here and/or call default
- if(pScrollBar->m_hWnd==m_ctlProgress.m_hWnd&&m_bPlay)
- {
- PlayM4_SetPlayedTimeEx(USED_PORT,m_iTotalSeconds*m_ctlProgress.GetPos()*10);
- }
- else if(pScrollBar->m_hWnd==m_ctlVolume.m_hWnd&&m_bSound)
- {
- PlayM4_SetVolume(USED_PORT,(WORD)m_ctlVolume.GetPos());
- }
- CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
- }
- void CLocalFilePlay::OnLButtonDblClk(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- if(IsInWnd(point)&&m_bPlay)
- {
- m_bFullScreen=!m_bFullScreen;
- if(m_bFullScreen)
- F_ShowFullScreen();
- else
- F_ShowNormal();
- PlayM4_RefreshPlay(USED_PORT);
- }
- CDialog::OnLButtonDblClk(nFlags, point);
- }
- BOOL CLocalFilePlay::IsInWnd(CPoint point)
- {
- CRect rc;
- GetDlgItem(IDC_WND)->GetWindowRect(&rc);
- ScreenToClient(&rc);
- if(PtInRect(&rc,point))
- return TRUE;
- else
- return FALSE;
- }
- void CLocalFilePlay::OnPaint()
- {
- CPaintDC dc(this); // device context for painting
-
- // TODO: Add your message handler code here
- CWnd *pWnd=GetDlgItem(IDC_WND);
- pWnd->Invalidate();
- pWnd->UpdateWindow();
-
- PlayM4_RefreshPlay(USED_PORT);
- // Do not call CDialog::OnPaint() for painting messages
- }
- void CLocalFilePlay::OnTimer(UINT nIDEvent)
- {
- // TODO: Add your message handler code here and/or call default
- if(nIDEvent==PLAY_TIMER)
- {
- F_ShowStatus();
- }
- CDialog::OnTimer(nIDEvent);
- }
- void CLocalFilePlay::F_ShowStatus()
- {
- //保护。
- if(m_iTotalSeconds<=0)
- return;
- DWORD nCurSecond=PlayM4_GetPlayedTime(USED_PORT);
- m_ctlProgress.SetPos(nCurSecond*100/m_iTotalSeconds);
- CString csStatus;
- csStatus.Format("%02d:%02d:%02d/%02d:%02d:%02d",\
- nCurSecond/3600,(nCurSecond%3600)/60,nCurSecond%60,\
- m_iTotalSeconds/3600,(m_iTotalSeconds%3600)/60,m_iTotalSeconds%60);
-
- GetDlgItem(IDC_PLAYSTATUS)->SetWindowText(csStatus);
- }
- void CLocalFilePlay::F_Stop()
- {
- m_bPause=FALSE;
- if(m_bPlay)
- {
- m_bPlay=FALSE;
- PlayM4_Stop(USED_PORT);
- PlayM4_CloseFile(USED_PORT);
- if(m_bSound)
- F_Sound(FALSE);
- F_SetStopState();
- }
- }
- void CLocalFilePlay::F_InitUI()
- {
- // 初始化按钮
- CButton *pButton;
-
- m_rcScreen=CRect(0,0,GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN));
- //初始化滑动条
- m_ctlProgress.SetRange(0,100);
- m_ctlProgress.SetPos(0);
- m_ctlVolume.SetRange(0,0xffff);
- m_ctlVolume.SetPos(0x7fff);
- m_ctlProgress.EnableWindow(FALSE);
- m_ctlVolume.EnableWindow(FALSE);
-
- pButton = (CButton *)GetDlgItem(IDC_PLAY_FILE);
- pButton->SetIcon(m_hPlayDisableIcon);
- pButton->EnableWindow(FALSE);
-
- pButton = (CButton *)GetDlgItem(IDC_STOP);
- pButton->SetIcon(m_hStopDisableIcon);
- pButton->EnableWindow(FALSE);
-
- pButton = (CButton *)GetDlgItem(IDC_FAST);
- pButton->SetIcon(m_hFastDisableIcon);
- pButton->EnableWindow(FALSE);
-
- pButton = (CButton *)GetDlgItem(IDC_SLOW);
- pButton->SetIcon(m_hSlowDisableIcon);
- pButton->EnableWindow(FALSE);
-
- pButton = (CButton *)GetDlgItem(IDC_STEP);
- pButton->SetIcon(m_hStepDisableIcon);
- pButton->EnableWindow(FALSE);
-
- pButton = (CButton *)GetDlgItem(IDC_STEPBACK);
- pButton->SetIcon(m_hStepBackDisableIcon);
- pButton->EnableWindow(FALSE);
-
- pButton = (CButton *)GetDlgItem(IDC_CAPPIC);
- pButton->SetIcon(m_hCaptureIcon);
- pButton->EnableWindow(FALSE);
-
- pButton = (CButton *)GetDlgItem(IDC_SOUND);
- pButton->SetIcon(m_hSoundStopIcon);
- pButton->EnableWindow(FALSE);
- }
- /*****************************************************
- 功能:检查起始和终止时间
- ******************************************************/
- BOOL CLocalFilePlay::F_CheckDate(CTime tFrom, CTime tTo)
- {
- if(tFrom.GetYear() > tTo.GetYear())
- return FALSE;
- else
- {
- if(tFrom.GetYear() == tTo.GetYear())
- {
- if(tFrom.GetMonth() > tTo.GetMonth())
- return FALSE;
- else
- {
- if(tFrom.GetMonth() == tTo.GetMonth())
- {
- if(tFrom.GetDay() > tTo.GetDay())
- return FALSE;
- else
- {
- if(tFrom.GetDay() == tTo.GetDay())
- {
- if(tFrom.GetHour() > tTo.GetHour())
- return FALSE;
- else
- {
- if(tFrom.GetHour() == tTo.GetHour())
- {
- if(tFrom.GetMinute() > tTo.GetMinute())
- return FALSE;
- else
- {
- if(tFrom.GetMinute() == tTo.GetMinute())
- {
- if(tFrom.GetSecond() > tTo.GetSecond())
- return FALSE;
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- return TRUE;
- }
- /*************************************
- 功能:查找下载文件显示在LIST中
- iFileType:1-正常,2-报警,3-下载
- **************************************/
- int CLocalFilePlay::F_ShowlocalFile(CString csIP,int iFileType,int iChanNum, CTime tFrom, CTime tTo)
- {
- CString sTemp, sTemp1;
- UINT i=0; int j;
- CTime tFileTime;
- CString csType;
- CString csDir, csChildDir, csFindFile, csFileName;
- CFileFind fddirectory,fdmpeg4file;
- BOOL bFinded, bFindFile;
- CNewclientApp* pApp = (CNewclientApp*)AfxGetApp();
- switch(iFileType)
- {
- case 1:
- csType.Format(_T("正常"));
- for(j = ClientParam.m_iStartRecordDriver; j < ClientParam.m_iEndRecordDriver + 1; j++)
- {
- csDir.Format("%c:\\mpeg4record\\*.*", pApp->m_cHardDriver[j]);
- bFinded=fddirectory.FindFile(csDir);
- while(bFinded)
- {
- bFinded=fddirectory.FindNextFile();
- if (fddirectory.IsDots())
- {
- continue;
- }
- if (fddirectory.IsDirectory())
- {
- csChildDir.Format("%c:\\mpeg4record\\%s",pApp->m_cHardDriver[j],fddirectory.GetFileName());
- csFindFile.Format("%s\\%s_%02d*.mp4",csChildDir, csIP, iChanNum);
- TRACE("Begin to find the following files: %s", csFindFile);
- bFindFile=fdmpeg4file.FindFile(csFindFile);
- while(bFindFile)
- {
- bFindFile = fdmpeg4file.FindNextFile();
- if(fdmpeg4file.IsDots())
- continue;
- csFileName.Format("%s\\%s", csChildDir, fdmpeg4file.GetFileName());
- TRACE("The finded file name: %s", csFileName);
- fdmpeg4file.GetCreationTime(tFileTime);
- if(F_CheckDate(tFrom, tFileTime) && F_CheckDate(tFileTime, tTo))
- {
- m_locFileList.InsertItem(m_iTSum,csFileName,0);
- sTemp.Format("%d",iChanNum);
- m_locFileList.SetItemText(m_iTSum,1,sTemp);
- m_locFileList.SetItemText(m_iTSum,2,csType);
- m_locFileList.SetItemText(m_iTSum,3,tFileTime.Format("%Y%m%d %H:%M:%S"));
- fdmpeg4file.GetLastWriteTime(tFileTime);
- m_locFileList.SetItemText(m_iTSum,4,tFileTime.Format("%Y%m%d %H:%M:%S"));
- i++;
- m_iTSum++;
- }
- }
- }
- }
- }
- break;
- case 2:
- break;
- case 3:
- i = F_ShowDownloadFile(csIP, iChanNum, tFrom, tTo);
- break;
- default:
- return 0;
- break;
- }
- return i;
- }
- int CLocalFilePlay::F_ShowDownloadFile(CString csIP,int iChanNum, CTime tFrom, CTime tTo)
- {
- //显示文件名称
- char buffer[200];
- char buf_channel[4];
- CString sTemp, sTemp1;
- int i=0;
- WIN32_FIND_DATA FindFileData;
- HANDLE hFind;
- CTime tFileTime;
- CString csType;
-
- sprintf(buf_channel,"%02d",iChanNum);
- strcpy(buffer,ClientParam.m_csDownLoadPath);
- strcat(buffer,"\\");
- strcat(buffer,csIP);
- strcat(buffer,"_");
- strcat(buffer,buf_channel);
- strcat(buffer,"_D*.mp4");
- csType.Format(_T("下载"));
- sTemp1.Format("%s", ClientParam.m_csDownLoadPath);
-
- hFind = FindFirstFile(buffer, &FindFileData);
- if (hFind == INVALID_HANDLE_VALUE)
- {
- FindClose(hFind);
- return 0;
- }
- else
- {
- tFileTime = CTime((const FILETIME&)(FindFileData.ftCreationTime));
- if (F_CheckDate( tFrom, tFileTime) && F_CheckDate(tFileTime, tTo))
- {
- sTemp.Format("%s\\%s",sTemp1,FindFileData.cFileName);
- m_locFileList.InsertItem(m_iTSum,sTemp,0);
- sTemp.Format("%d",iChanNum);
- m_locFileList.SetItemText(m_iTSum,1,sTemp);
- m_locFileList.SetItemText(m_iTSum,2,csType);
- m_locFileList.SetItemText(m_iTSum,3,tFileTime.Format("%Y%m%d %H:%M:%S"));
- tFileTime = CTime( (const FILETIME&)(FindFileData.ftLastWriteTime));
- m_locFileList.SetItemText(m_iTSum,4,tFileTime.Format("%Y%m%d %H:%M:%S"));
- i++;
- m_iTSum++;
- }
- }
- while (FindNextFile(hFind,&FindFileData))
- {
- tFileTime = CTime( (const FILETIME&)(FindFileData.ftCreationTime));
- if (F_CheckDate(tFrom, tFileTime) && F_CheckDate(tFileTime, tTo))
- {
- sTemp.Format("%s\\%s",sTemp1,FindFileData.cFileName);
- m_locFileList.InsertItem(m_iTSum,sTemp,0);
- sTemp.Format("%d",iChanNum);
- m_locFileList.SetItemText(m_iTSum,1,sTemp);
- m_locFileList.SetItemText(m_iTSum,2,csType);
- m_locFileList.SetItemText(m_iTSum,3,tFileTime.Format("%Y%m%d %H:%M:%S"));
- tFileTime = CTime( (const FILETIME&)(FindFileData.ftLastWriteTime));
- m_locFileList.SetItemText(m_iTSum,4,tFileTime.Format("%Y%m%d %H:%M:%S"));
- i++;
- m_iTSum++;
- }
- }
- return i;
- }
- void CLocalFilePlay::F_SetStopState()
- {
- CButton *pButton;
-
- m_ctlProgress.SetPos(0);
- m_ctlProgress.EnableWindow(FALSE);
- m_ctlVolume.EnableWindow(FALSE);
-
- pButton = (CButton *)GetDlgItem(IDC_PLAY_FILE);
- pButton->SetIcon(m_hPlayEnableIcon);
- pButton->EnableWindow(TRUE);
-
- pButton = (CButton *)GetDlgItem(IDC_STOP);
- pButton->SetIcon(m_hStopDisableIcon);
- pButton->EnableWindow(FALSE);
-
- pButton = (CButton *)GetDlgItem(IDC_FAST);
- pButton->SetIcon(m_hFastDisableIcon);
- pButton->EnableWindow(FALSE);
-
- pButton = (CButton *)GetDlgItem(IDC_SLOW);
- pButton->SetIcon(m_hSlowDisableIcon);
- pButton->EnableWindow(FALSE);
-
- pButton = (CButton *)GetDlgItem(IDC_STEP);
- pButton->SetIcon(m_hStepDisableIcon);
- pButton->EnableWindow(FALSE);
-
- pButton = (CButton *)GetDlgItem(IDC_STEPBACK);
- pButton->SetIcon(m_hStepBackDisableIcon);
- pButton->EnableWindow(FALSE);
-
- pButton = (CButton *)GetDlgItem(IDC_CAPPIC);
- pButton->SetIcon(m_hCaptureIcon);
- pButton->EnableWindow(FALSE);
-
- pButton = (CButton *)GetDlgItem(IDC_SOUND);
- pButton->SetIcon(m_hSoundStopIcon);
- pButton->EnableWindow(FALSE);
- pButton = (CButton *)GetDlgItem(IDC_STEP);
- pButton->SetIcon(m_hStepDisableIcon);
- pButton->EnableWindow(FALSE);
-
- F_UpdateStepBackUI(FALSE);
- }
- void CLocalFilePlay::F_UpdateStepBackUI(BOOL bEnable)
- {
- m_bFileRefCreated=bEnable;
- CButton *pButton;
- if(m_bFileRefCreated)
- {
- pButton = (CButton *)GetDlgItem(IDC_STEPBACK);
- pButton->SetIcon(m_hStepBackEnableIcon);
- pButton->EnableWindow(TRUE);
- }
- else
- {
- pButton = (CButton *)GetDlgItem(IDC_STEPBACK);
- pButton->SetIcon(m_hStepBackDisableIcon);
- pButton->EnableWindow(FALSE);
- }
- }
- void CLocalFilePlay::F_SetPlayState()
- {
- CButton *pButton;
-
- m_ctlProgress.EnableWindow(TRUE);
- m_ctlVolume.EnableWindow(TRUE);
-
- pButton = (CButton *)GetDlgItem(IDC_PLAY_FILE);
- pButton->SetIcon(m_hPauseEnableIcon);
- pButton->EnableWindow(TRUE);
-
- pButton = (CButton *)GetDlgItem(IDC_STOP);
- pButton->SetIcon(m_hStopEnableIcon);
- pButton->EnableWindow(TRUE);
-
- pButton = (CButton *)GetDlgItem(IDC_FAST);
- pButton->SetIcon(m_hFastEnableIcon);
- pButton->EnableWindow(TRUE);
-
- pButton = (CButton *)GetDlgItem(IDC_SLOW);
- pButton->SetIcon(m_hSlowEnableIcon);
- pButton->EnableWindow(TRUE);
-
- pButton = (CButton *)GetDlgItem(IDC_CAPPIC);
- pButton->SetIcon(m_hCaptureIcon);
- pButton->EnableWindow(TRUE);
-
- pButton = (CButton *)GetDlgItem(IDC_SOUND);
- if(m_bSound)
- pButton->SetIcon(m_hSoundStartIcon);
- else
- pButton->SetIcon(m_hSoundStopIcon);
- pButton->EnableWindow(TRUE);
-
- pButton = (CButton *)GetDlgItem(IDC_STEP);
- pButton->SetIcon(m_hStepEnableIcon);
- pButton->EnableWindow(TRUE);
-
- }
- void CLocalFilePlay::F_SetPauseState()
- {
- CButton *pButton;
- pButton = (CButton *)GetDlgItem(IDC_PLAY_FILE);
- pButton->SetIcon(m_hPlayEnableIcon);
- pButton->EnableWindow(TRUE);
- }
- void CLocalFilePlay::F_Play()
- {
- int fileselpos = 0;
- CString csFileName;
- CString csIP,csTemp, sTemp1;
- int nPos = 0;
-
- UpdateData(TRUE);
- POSITION pos = m_locFileList.GetFirstSelectedItemPosition();
- if(pos == NULL)
- {
- AfxMessageBox("请选择要播放的文件!");
- return;
- }
- fileselpos = m_locFileList.GetNextSelectedItem(pos);
-
- PlayM4_SetFileRefCallBack(USED_PORT,FileRefDone,(DWORD)this);
- csFileName = m_locFileList.GetItemText(fileselpos,0);
- if(csFileName.GetLength()==0)
- return;
- csTemp.Format("%s",csFileName);
- nPos=csTemp.Find("\\",0);
- while(nPos>=0)
- {
- csIP.Format("%s",csTemp.Right(csTemp.GetLength()-nPos-1));
- csTemp.Format("%s",csIP);
- nPos=csTemp.Find("\\",0);
- }
- nPos=csTemp.Find("_",0);
- csIP.Format("%s",csTemp.Left(nPos));
- m_csIP.Format("%s",csIP);
- if(!PlayM4_OpenFile(USED_PORT,csFileName.GetBuffer(csFileName.GetLength())))
- {
- TRACE("open file failed!");
- return;
- }
- sTemp1 = m_locFileList.GetItemText(fileselpos,1);
- TRACE("Play file of %s", sTemp1);
- iSelChannel = atoi(sTemp1);
- TRACE("iSelChannel = %d", iSelChannel);
- m_iTotalSeconds=PlayM4_GetFileTime(USED_PORT);
- if(m_iTotalSeconds<=0)
- {
- PlayM4_CloseFile(USED_PORT);
- MessageBox("文件大小为0!");
- return;
- }
- PlayM4_SetDisplayCallBack(USED_PORT,DisplayCBFun);
- if((m_bPlay=PlayM4_Play(USED_PORT,m_hPlayWnd))==FALSE)
- {
- PlayM4_CloseFile(USED_PORT);
- TRACE("play file error!");
- return;
- }
- }
- void CLocalFilePlay::F_Pause()
- {
- if(PlayM4_Pause(USED_PORT,!m_bPause))
- {
- m_bPause=!m_bPause;
- }
- else
- {
- TRACE("PAUSE ERROR!");
- }
- if(m_bPause)
- F_SetPauseState();
- else
- F_SetPlayState();
- }
- void CLocalFilePlay::F_Sound(BOOL bSound)
- {
- if(!m_bPlay)
- return;
- if(bSound)
- {
- m_bSound=PlayM4_PlaySound(USED_PORT);
- PlayM4_SetVolume(USED_PORT,(WORD)m_ctlVolume.GetPos());
- }
- else
- {
- PlayM4_StopSound();
- m_bSound=FALSE;
- }
- if(m_bSound)
- F_SetPlaySoundState();
- else
- F_SetStopSoundState();
-
- }
- void CLocalFilePlay::F_SetPlaySoundState()
- {
- CButton *pButton;
- pButton = (CButton *)GetDlgItem(IDC_SOUND);
- pButton->SetIcon(m_hSoundStartIcon);
- pButton->EnableWindow(TRUE);
-
- }
- void CLocalFilePlay::F_SetStopSoundState()
- {
- CButton *pButton;
- pButton = (CButton *)GetDlgItem(IDC_SOUND);
- pButton->SetIcon(m_hSoundStopIcon);
- pButton->EnableWindow(TRUE);
- }
- void CLocalFilePlay::F_ShowFullScreen()
- {
- F_EnableFlashWnd(FALSE);
- CRect rc,rcClient;
- ::GetWindowRect(m_hPareDlgWnd,m_rcPareDlg);
-
- ::GetWindowRect(m_hPareTabWnd,m_rcPareTab);
- ::ScreenToClient(m_hPareDlgWnd,(POINT*)(&m_rcPareTab));
- ::ScreenToClient(m_hPareDlgWnd,(POINT*)(&m_rcPareTab)+1);
-
- ::GetWindowRect(m_hWnd,m_rcParent);
- ::ScreenToClient(m_hPareTabWnd,(POINT*)(&m_rcParent));
- ::ScreenToClient(m_hPareTabWnd,(POINT*)(&m_rcParent)+1);
-
-
- ::SetWindowPos(m_hPareDlgWnd,NULL,m_rcScreen.left-SCREEN_EDGE,m_rcScreen.top-SCREEN_EDGE,m_rcScreen.Width()+2*SCREEN_EDGE,m_rcScreen.Height()+2*SCREEN_EDGE,SWP_SHOWWINDOW);
-
- ::GetClientRect(m_hPareDlgWnd,rc);
- ::SetWindowPos(m_hPareTabWnd,NULL,rc.left,rc.top,rc.Width(),rc.Height(),SWP_SHOWWINDOW);
-
- ::GetClientRect(m_hPareTabWnd,rc);
- ::SetWindowPos(m_hWnd,NULL,rc.left,rc.top,rc.Width(),rc.Height(),SWP_SHOWWINDOW);
-
- GetDlgItem(IDC_WND)->GetClientRect(rcClient);
- GetDlgItem(IDC_WND)->GetWindowRect(rc);
- int iEdge=(rc.Width()-rcClient.Width())/2;
- rc=m_rcScreen;
- rc.left-=iEdge;
- rc.right+=iEdge;
- rc.top-=iEdge;
- rc.bottom+=iEdge;
- this->ScreenToClient(rc);
- ::SetWindowPos(GetDlgItem(IDC_WND)->m_hWnd,NULL,rc.left,rc.top,rc.Width(),rc.Height(),SWP_SHOWWINDOW);
- Invalidate(FALSE);
- UpdateWindow();
- }
- void CLocalFilePlay::F_ShowNormal()
- {
-
- GetDlgItem(IDC_WND)->SetWindowPos(NULL,m_rcWnd.left,m_rcWnd.top,m_rcWnd.Width(),m_rcWnd.Height(),SWP_SHOWWINDOW);
- ::SetWindowPos(m_hWnd,NULL,m_rcParent.left,m_rcParent.top,m_rcParent.Width(),m_rcParent.Height(),SWP_SHOWWINDOW);
- ::SetWindowPos(m_hPareTabWnd,NULL,m_rcPareTab.left,m_rcPareTab.top,m_rcPareTab.Width(),m_rcPareTab.Height(),SWP_SHOWWINDOW);
- ::SetWindowPos(m_hPareDlgWnd,NULL,m_rcPareDlg.left,m_rcPareDlg.top,m_rcPareDlg.Width(),m_rcPareDlg.Height(),SWP_SHOWWINDOW);
- F_EnableFlashWnd(TRUE);
- Invalidate(FALSE);
- UpdateWindow();
- }
- void CLocalFilePlay::F_EnableFlashWnd(BOOL bEnable)
- {
- if(bEnable)
- {
- //THE same to multiplay
- GetDlgItem(IDC_PLAYSTATUS)->ModifyStyle(0,WS_VISIBLE,0);
- GetDlgItem(IDC_PLAY_FILE)->ModifyStyle(0,WS_VISIBLE,0);
- GetDlgItem(IDC_STOP)->ModifyStyle(0,WS_VISIBLE,0);
- GetDlgItem(IDC_SLOW)->ModifyStyle(0,WS_VISIBLE,0);
- GetDlgItem(IDC_FAST)->ModifyStyle(0,WS_VISIBLE,0);
- GetDlgItem(IDC_SOUND)->ModifyStyle(0,WS_VISIBLE,0);
- GetDlgItem(IDC_VOLUME_SLIDER)->ModifyStyle(0,WS_VISIBLE,0);
- GetDlgItem(IDC_DATESTART)->ModifyStyle(0,WS_VISIBLE,0);
- GetDlgItem(IDC_DATESTOP)->ModifyStyle(0,WS_VISIBLE,0);
- GetDlgItem(IDC_TIMESTOP)->ModifyStyle(0,WS_VISIBLE,0);
- GetDlgItem(IDC_TIMESTART)->ModifyStyle(0,WS_VISIBLE,0);
- GetDlgItem(IDC_COMBOFILETYPE)->ModifyStyle(0,WS_VISIBLE,0);
- GetDlgItem(IDC_SEARCHLOCALLIST)->ModifyStyle(0,WS_VISIBLE,0);
- GetDlgItem(IDC_PROGRESS_SLIDER)->ModifyStyle(0,WS_VISIBLE,0);
- GetDlgItem(IDC_CAPPIC)->ModifyStyle(0,WS_VISIBLE,0);
-
- //the only for single play
- GetDlgItem(IDC_LOCALFILRLIST)->ModifyStyle(0,WS_VISIBLE,0);
- GetDlgItem(IDC_STEP)->ModifyStyle(0,WS_VISIBLE,0);
- GetDlgItem(IDC_STEPBACK)->ModifyStyle(0,WS_VISIBLE,0);
- GetDlgItem(IDC_DELETEALL)->ModifyStyle(0,WS_VISIBLE,0);
- GetDlgItem(IDC_DELETE)->ModifyStyle(0,WS_VISIBLE,0);
- GetDlgItem(IDC_COMBOCHANNEL)->ModifyStyle(0,WS_VISIBLE,0);
-
- }
- else
- {
- //THE same to multiplay
- GetDlgItem(IDC_PLAYSTATUS)->ModifyStyle(WS_VISIBLE,0,0);
- GetDlgItem(IDC_PLAY_FILE)->ModifyStyle(WS_VISIBLE,0,0);
- GetDlgItem(IDC_STOP)->ModifyStyle(WS_VISIBLE,0,0);
- GetDlgItem(IDC_SLOW)->ModifyStyle(WS_VISIBLE,0,0);
- GetDlgItem(IDC_FAST)->ModifyStyle(WS_VISIBLE,0,0);
- GetDlgItem(IDC_SOUND)->ModifyStyle(WS_VISIBLE,0,0);
- GetDlgItem(IDC_VOLUME_SLIDER)->ModifyStyle(WS_VISIBLE,0,0);
- GetDlgItem(IDC_PROGRESS_SLIDER)->ModifyStyle(WS_VISIBLE,0,0);
- GetDlgItem(IDC_DATESTART)->ModifyStyle(WS_VISIBLE,0,0);
- GetDlgItem(IDC_DATESTOP)->ModifyStyle(WS_VISIBLE,0,0);
- GetDlgItem(IDC_TIMESTOP)->ModifyStyle(WS_VISIBLE,0,0);
- GetDlgItem(IDC_TIMESTART)->ModifyStyle(WS_VISIBLE,0,0);
- GetDlgItem(IDC_COMBOFILETYPE)->ModifyStyle(WS_VISIBLE,0,0);
- GetDlgItem(IDC_SEARCHLOCALLIST)->ModifyStyle(WS_VISIBLE,0,0);
- GetDlgItem(IDC_CAPPIC)->ModifyStyle(WS_VISIBLE,0,0);
-
- //the only for single play
- GetDlgItem(IDC_LOCALFILRLIST)->ModifyStyle(WS_VISIBLE,0,0);
- GetDlgItem(IDC_STEP)->ModifyStyle(WS_VISIBLE,0,0);
- GetDlgItem(IDC_STEPBACK)->ModifyStyle(WS_VISIBLE,0,0);
- GetDlgItem(IDC_DELETEALL)->ModifyStyle(WS_VISIBLE,0,0);
- GetDlgItem(IDC_DELETE)->ModifyStyle(WS_VISIBLE,0,0);
- GetDlgItem(IDC_COMBOCHANNEL)->ModifyStyle(WS_VISIBLE,0,0);
- }
- }
- void CLocalFilePlay::OnCancel()
- {
- // TODO: Add extra cleanup here
-
- //CDialog::OnCancel();
- }
- void CLocalFilePlay::OnSelchangeComboserver()
- {
- // TODO: Add your control notification handler code here
- int iSelServer = m_ServerCtrl.GetCurSel() - 1;
- if(iSelServer < 0)
- return;
- LONG m_lServerID = serverinfo[iSelServer].m_lServerID;
- LONG m_lServerType = serverinfo[iSelServer].m_wServerType;
- m_lStartChan = serverinfo[iSelServer].m_lStartChannel;
- m_iChannelnumber = serverinfo[iSelServer].m_iServerChannelNumber;
- m_ChannelCtrl.ResetContent();
- CString sTemp;
- m_ChannelCtrl.AddString("全部通道");
- for(int i=0; i<m_iChannelnumber; i++)
- {
- sTemp.Format("%d", i+m_lStartChan);
- m_ChannelCtrl.AddString(sTemp);
- }
- m_ChannelCtrl.SetCurSel(0);
- }
- void CLocalFilePlay::OnSelchangeCombofiletype()
- {
- // TODO: Add your control notification handler code here
- }
|