From 89cd7441c184d37f90d4d5311b348e938119765f Mon Sep 17 00:00:00 2001
From: zxd <zxdvslxy@gmail.com>
Date: 星期六, 21 十月 2023 12:28:04 +0800
Subject: [PATCH] 修改最后一个单元格不会被读取的问题

---
 MTerm2/DialogEventLog.cpp |  112 ++++++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 88 insertions(+), 24 deletions(-)

diff --git a/MTerm2/DialogEventLog.cpp b/MTerm2/DialogEventLog.cpp
index f1fe66f..e87652c 100644
--- a/MTerm2/DialogEventLog.cpp
+++ b/MTerm2/DialogEventLog.cpp
@@ -32,6 +32,7 @@
 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()
 
 KLink::stEventLog KEventLogs[20000];
@@ -87,6 +88,7 @@
 
 	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);
@@ -95,29 +97,14 @@
 	int nStartIndex = 0;
 	int nReadCount = 1;
 	m_list_eventlog.DeleteAllItems();
-	for (int i = 0; i < nCount; i++)
-	{
-		res = pDoc->MyKLink1.GetEventLog(1, i, nReadCount, &KEventLogs[i]);
-		s1.Format(_T(" Get EventLog %d Result r=%d "),i, res);
-		s1.AppendFormat(_T("%d %d %d %d %d %d"), KEventLogs[i].Sign1, KEventLogs[i].Seq1, KEventLogs[i].nTime, KEventLogs[i].nType, KEventLogs[i].nParam1, KEventLogs[i].nParam2);
-		// SysLog(s1);
-		s1.Format(_T("%d"), i);
-		m_list_eventlog.InsertItem(i, s1);
-		s1.Format(_T("%d"), KEventLogs[i].Seq1);
-		m_list_eventlog.SetItemText(i, 1, s1);
 
-		s1.Format(_T("%d"), KEventLogs[i].nTime);
-		CTime ctime1 = KEventLogs[i].nTime;
-		s1 = ctime1.Format(_T("%Y-%m-%d %H:%M:%S"));
-
-		m_list_eventlog.SetItemText(i, 2, s1);
-		s1.Format(_T("%d"), KEventLogs[i].nType);
-		m_list_eventlog.SetItemText(i, 3, s1);
-		s1.Format(_T("%d"), KEventLogs[i].nParam1);
-		m_list_eventlog.SetItemText(i, 4, s1);
-		s1.Format(_T("%d"), KEventLogs[i].nParam2);
-		m_list_eventlog.SetItemText(i, 5, s1);
-	}
+	m_nEventCount = nCount;
+	m_nCurEvent = 0;
+	SetTimer(1, 100, NULL);
+//	for (int i = 0; i < nCount; i++)
+//	{
+//		GetEventLogByIndex(i);
+//	}
 
 	return 0;
 }
@@ -138,10 +125,87 @@
 	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
 
-	GetEventLogStatus();
-	UpLoadEventLog();
+	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();
+	CMTerm2Doc* pDoc = (CMTerm2Doc *)(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: 鍦ㄦ娣诲姞娑堟伅澶勭悊绋嬪簭浠g爜鍜�/鎴栬皟鐢ㄩ粯璁ゅ��
+	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;
+}

--
Gitblit v1.9.1