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

📄 eventlog.cpp

📁 SDK DVR/DVS HIKVISION
💻 CPP
字号:
// EventLog.cpp : implementation file
//

#include "stdafx.h"
#include "newclient.h"
#include "EventLog.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

extern	CLIENTPARAM	ClientParam;
static	int	iEventPos = 0;
#define	EVENTNUM	2000
CString	csEventTime[EVENTNUM];
CString	csEventInfo[EVENTNUM]; 

/////////////////////////////////////////////////////////////////////////////
// CEventLog dialog

void F_AddEvent(CString csEvent)
{
	CEventLog m_eventlog;
	
	m_eventlog.AddEvent(csEvent);	
}


CEventLog::CEventLog(CWnd* pParent /*=NULL*/)
	: CDialog(CEventLog::IDD, pParent)
{
	//{{AFX_DATA_INIT(CEventLog)
	//}}AFX_DATA_INIT
}


void CEventLog::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CEventLog)
	DDX_Control(pDX, IDC_LIST1, m_list);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CEventLog, CDialog)
	//{{AFX_MSG_MAP(CEventLog)
	ON_BN_CLICKED(IDC_BUTTONSAVE, OnButtonsave)
	ON_BN_CLICKED(IDEXIT, OnExit)
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CEventLog message handlers

void CEventLog::AddEvent(CString csEvent)
{
	CTime time = CTime::GetCurrentTime();
	csEventTime[iEventPos].Format("%04d-%02d-%02d %02d:%02d:%02d", time.GetYear(), time.GetMonth(), time.GetDay(), time.GetHour(), time.GetMinute(), time.GetSecond());
	csEventInfo[iEventPos].Format("%s", csEvent);
	iEventPos++;
	if(iEventPos >= EVENTNUM)
	{
		iEventPos = 0;
	}
}

void CEventLog::OnButtonsave() 
{
	// TODO: Add your control notification handler code here
	CString sFileName;
	CTime time;
	
	if(iEventPos == 0)
		return;
	time = CTime::GetCurrentTime();
	sFileName.Format("%s\\EventFile_%4d%02d%02d_%02d%02d%02d.txt", ClientParam.m_csLogSavePath, time.GetYear(), time.GetMonth(), time.GetDay(), time.GetHour(), time.GetMinute(), time.GetSecond());
	F_SaveEventFile(sFileName);
	F_InitList();
	m_bSave = TRUE;
}

void CEventLog::F_SaveEventFile(CString csFileName)
{
	int i;
	CString sTemp;
	CStdioFile myFile;
	
	if(myFile.Open(csFileName, CFile::modeCreate|CFile::modeWrite) == FALSE)
	{
		AfxMessageBox("Create log file failed!");
		return;
	}
	for(i = 0; i < iEventPos; i++)
	{
		sTemp.Format("%s %s\r\n", csEventTime[i], csEventInfo[i]);
		myFile.WriteString(sTemp);
	}
	myFile.Close();
	iEventPos = 0;
}

BOOL CEventLog::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here

	m_bSave = FALSE;
	m_nTimer = 0;
	m_list.InsertColumn(0,"Time",LVCFMT_LEFT,120,-1);
	m_list.InsertColumn(1,"Event Description",LVCFMT_LEFT,600,-1);
	F_InitList();
	m_nTimer = SetTimer(EVENTLOG_TIMER, 1000, NULL);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CEventLog::F_InitList()
{
	int i;
	
	m_list.DeleteAllItems();
	for(i = 0; i < iEventPos; i++)
	{
		m_list.InsertItem(i, csEventTime[i]);
		m_list.SetItemText(i, 1, csEventInfo[i]);
	}
}

void CEventLog::OnExit() 
{
	// TODO: Add your control notification handler code here
	if(m_nTimer)
	{
		KillTimer(EVENTLOG_TIMER);
	}
	CDialog::OnCancel();
}

void CEventLog::OnCancel() 
{
	// TODO: Add your control notification handler code here
	
}

void CEventLog::OnOK() 
{
	// TODO: Add extra cleanup here
	
	//	CDialog::OnOK();
}

void CEventLog::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	if(nIDEvent == EVENTLOG_TIMER)
	{
	}
	CDialog::OnTimer(nIDEvent);
}

⌨️ 快捷键说明

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