// CDialogEventLog.cpp: 实现文件 // #include "pch.h" #include "MTerm1.h" #include "DialogEventLog.h" #include "afxdialogex.h" #include "KLinkDefine.h" //#include "KLink.h" #include "MTerm1Doc.h" // CDialogEventLog 对话框 IMPLEMENT_DYNAMIC(CDialogEventLog, CDialogEx) CDialogEventLog::CDialogEventLog(CWnd* pParent /*=nullptr*/) : CDialogEx(IDD_DIALOG_EVENTLOG, pParent) { } CDialogEventLog::~CDialogEventLog() { } void CDialogEventLog::DoDataExchange(CDataExchange* pDX) { CDialogEx::DoDataExchange(pDX); DDX_Control(pDX, IDC_LIST_EVENTLOG, m_list_eventlog); } BEGIN_MESSAGE_MAP(CDialogEventLog, CDialogEx) ON_BN_CLICKED(IDC_BUTTON_CLEAR_EVENTLOG, &CDialogEventLog::OnBnClickedButtonClearEventlog) ON_BN_CLICKED(IDC_BUTTON_RELOAD, &CDialogEventLog::OnBnClickedButtonReload) ON_WM_TIMER() END_MESSAGE_MAP() KLink1::stEventLog KEventLogs[20000]; // CDialogEventLog 消息处理程序 void CDialogEventLog::OnBnClickedButtonReload() { // TODO: 在此添加控件通知处理程序代码 GetEventLogStatus(); UpLoadEventLog(); } void CDialogEventLog::OnBnClickedButtonClearEventlog() { // TODO: 在此添加控件通知处理程序代码 } int CDialogEventLog::GetEventLogStatus() { // TODO: 在此处添加实现代码. CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd; CMDIChildWnd *pChild = (CMDIChildWnd *)pFrame->GetActiveFrame(); CView *pV = (CView*)pChild->GetActiveView(); CMTerm1Doc* pDoc = (CMTerm1Doc *)(pV->GetDocument()); int nCount; int res = pDoc->MyKLink1.GetEventLogCount(1, &nCount); CString s1; s1.Format(_T("Get EventLogCount Result r=%d N=%d "), res, nCount); SysLog(s1); if (res == pDoc->MyKLink1.KL_OK) { s1.Format(_T("%d"), nCount); GetDlgItem(IDC_EDIT_EVENT_COUNT)->SetWindowText(s1); } return 0; } int CDialogEventLog::UpLoadEventLog() { // TODO: 在此处添加实现代码. CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd; CMDIChildWnd *pChild = (CMDIChildWnd *)pFrame->GetActiveFrame(); CView *pV = (CView*)pChild->GetActiveView(); CMTerm1Doc* pDoc = (CMTerm1Doc *)(pV->GetDocument()); int nCount; int res = pDoc->MyKLink1.GetEventLogCount(1, &nCount); CString s1; s1.Format(_T("Get EventLogCount Result r=%d N=%d "), res, nCount); SysLog(s1); if (res == pDoc->MyKLink1.KL_OK) { s1.Format(_T("%d"), nCount); GetDlgItem(IDC_EDIT_EVENT_COUNT)->SetWindowText(s1); } int nStartIndex = 0; int nReadCount = 1; m_list_eventlog.DeleteAllItems(); m_nEventCount = nCount; m_nCurEvent = 0; SetTimer(1, 50, NULL); // for (int i = 0; i < nCount; i++) // { // GetEventLogByIndex(i); // } return 0; } BOOL CDialogEventLog::OnInitDialog() { CDialogEx::OnInitDialog(); // TODO: 在此添加额外的初始化 m_list_eventlog.SetExtendedStyle(LVS_EX_DOUBLEBUFFER | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_ONECLICKACTIVATE | LVS_EX_LABELTIP); m_list_eventlog.DeleteAllItems(); while (m_list_eventlog.DeleteColumn(0)); m_list_eventlog.InsertColumn(0, _T("NO"), LVCFMT_LEFT, 32, -1);//LVCFMT_LEFT, LVCFMT_RIGHT, or LVCFMT_CENTER m_list_eventlog.InsertColumn(1, _T("序列号"), LVCFMT_LEFT, 48, -1);//LVCFMT_LEFT, LVCFMT_RIGHT, or LVCFMT_CENTER m_list_eventlog.InsertColumn(2, _T("时间"), LVCFMT_LEFT, 128, -1);//LVCFMT_LEFT, LVCFMT_RIGHT, or LVCFMT_CENTER m_list_eventlog.InsertColumn(3, _T("类型"), LVCFMT_LEFT, 64, -1);//LVCFMT_LEFT, LVCFMT_RIGHT, or LVCFMT_CENTER m_list_eventlog.InsertColumn(4, _T("数据1"), LVCFMT_LEFT, 128, -1);//LVCFMT_LEFT, LVCFMT_RIGHT, or LVCFMT_CENTER m_list_eventlog.InsertColumn(5, _T("数据2"), LVCFMT_LEFT, 128, -1);//LVCFMT_LEFT, LVCFMT_RIGHT, or LVCFMT_CENTER SetTimer(0, 10, NULL); return TRUE; // return TRUE unless you set the focus to a control // 异常: OCX 属性页应返回 FALSE } int CDialogEventLog::DelayInit() { // TODO: 在此处添加实现代码. GetEventLogStatus(); UpLoadEventLog(); return 0; } int CDialogEventLog::GetEventLogByIndex(int nIndex) { // TODO: 在此处添加实现代码. CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd; CMDIChildWnd *pChild = (CMDIChildWnd *)pFrame->GetActiveFrame(); CView *pV = (CView*)pChild->GetActiveView(); CMTerm1Doc* pDoc = (CMTerm1Doc *)(pV->GetDocument()); int nReadCount = 1; int res; CString s1; res = pDoc->MyKLink1.GetEventLog(1, nIndex, nReadCount, &KEventLogs[nIndex]); s1.Format(_T(" Get EventLog %d Result r=%d "), nIndex, res); s1.AppendFormat(_T("%d %d %d %d %d %d"), KEventLogs[nIndex].Sign1, KEventLogs[nIndex].Seq1, KEventLogs[nIndex].nTime, KEventLogs[nIndex].nType, KEventLogs[nIndex].nParam1, KEventLogs[nIndex].nParam2); // SysLog(s1); s1.Format(_T("%d"), nIndex); m_list_eventlog.InsertItem(nIndex, s1); s1.Format(_T("%d"), KEventLogs[nIndex].Seq1); m_list_eventlog.SetItemText(nIndex, 1, s1); s1.Format(_T("%d"), KEventLogs[nIndex].nTime); CTime ctime1 = KEventLogs[nIndex].nTime; s1 = ctime1.Format(_T("%Y-%m-%d %H:%M:%S")); m_list_eventlog.SetItemText(nIndex, 2, s1); s1.Format(_T("%d"), KEventLogs[nIndex].nType); m_list_eventlog.SetItemText(nIndex, 3, s1); s1.Format(_T("%d"), KEventLogs[nIndex].nParam1); m_list_eventlog.SetItemText(nIndex, 4, s1); s1.Format(_T("%d"), KEventLogs[nIndex].nParam2); m_list_eventlog.SetItemText(nIndex, 5, s1); //m_list_eventlog.SetItemText(nIndex, 5, s1); return 0; } void CDialogEventLog::OnTimer(UINT_PTR nIDEvent) { // TODO: 在此添加消息处理程序代码和/或调用默认值 if (nIDEvent == 0) { KillTimer(0); DelayInit(); } else if (nIDEvent == 1) { GetEventProcess(); } else { } CDialogEx::OnTimer(nIDEvent); } int CDialogEventLog::GetEventProcess() { // TODO: 在此处添加实现代码. if (m_nCurEvent < m_nEventCount) { GetEventLogByIndex(m_nCurEvent); m_nCurEvent++; if (m_nCurEvent >= m_nEventCount) { KillTimer(1); } } return 0; }