From a85f4cc17f8775845a2d9dbc359826663ede2fe0 Mon Sep 17 00:00:00 2001
From: LYW <leeyeanwoo@diteam.co.kr>
Date: 금, 04 6월 2021 17:52:11 +0900
Subject: [PATCH] Ongoing80 #3417 CF AOI Review 전설비 Log Process개선 - LOG 뷰어 리스트 박스로 변경 - 시퀀스 쓰레드에서 로그 발생기 로그 쓰레드로 메시지로 전송 후 바로 다음 업무 처리

---
 ReviewSystem/ReviewSystem/DisplayMessage.h   |    6 ++
 ReviewSystem/ReviewSystem/ReviewSystem.rc    |    7 ++
 ReviewSystem/ReviewSystem/DisplayMessage.cpp |   70 +++++++++++++++++++----
 ReviewSystem/ReviewSystem/DlgLog.h           |    4 +
 ReviewSystem/ReviewSystem/resource.h         |    3 
 ReviewSystem/ReviewSystem/DlgLog.cpp         |   44 +++++++++-----
 6 files changed, 103 insertions(+), 31 deletions(-)

diff --git a/ReviewSystem/ReviewSystem/DisplayMessage.cpp b/ReviewSystem/ReviewSystem/DisplayMessage.cpp
index 8d7f0e2..1555229 100644
--- a/ReviewSystem/ReviewSystem/DisplayMessage.cpp
+++ b/ReviewSystem/ReviewSystem/DisplayMessage.cpp
@@ -8,6 +8,12 @@
 
 	SetPath(strPath);
 
+	// #3417 LYWCF AOI Review �쟾�꽕鍮� Log Process媛쒖꽑 ADD START
+	DWORD  dwThreadId = 0;
+	HANDLE hThread = CreateThread(NULL, 0, RunThreadDisplayLog, NULL, 0, &dwThreadId);
+	m_ThreadId = dwThreadId;
+	// #3417 LYWCF AOI Review �쟾�꽕鍮� Log Process媛쒖꽑 ADD END
+
 	InitializeCriticalSection(&m_csLog);
 }
 
@@ -18,6 +24,8 @@
 		delete m_pFileLog;
 		m_pFileLog = NULL;
 	}
+
+	PostThreadMessage(m_ThreadId, WM_QUIT, 0, 0);
 
 	DeleteCriticalSection(&m_csLog);
 }
@@ -50,17 +58,22 @@
 
 	return TRUE;
 }
-
+// #3417 LYWCF AOI Review �쟾�꽕鍮� Log Process媛쒖꽑 ADD START
 void CDisplayMessage::DisplayMessage(const CString& strMessage)
 {
-	WriteToFile(strMessage);
+// 	WriteToFile(strMessage);
+// 
+// 	if(m_pDM2P)
+// 	{
+// 		m_pDM2P->DM2P_DisplayMessage(strMessage);
+// 	}
+	CString* pstrLog = new CString(strMessage);
+	PostThreadMessage(m_ThreadId, WM_DIPLAY_LOG, reinterpret_cast<WPARAM>(pstrLog), 0);
 
-	if(m_pDM2P)
-	{
-		m_pDM2P->DM2P_DisplayMessage(strMessage);
-	}
 }
+// #3417 LYWCF AOI Review �쟾�꽕鍮� Log Process媛쒖꽑 ADD END
 
+// #3417 LYWCF AOI Review �쟾�꽕鍮� Log Process媛쒖꽑 ADD START
 void CDisplayMessage::DisplayMessage(const TCHAR* lpstrFormat, ...)
 {
 	va_list list;
@@ -70,11 +83,26 @@
 	_vstprintf_s(strText, lpstrFormat, list);
 	va_end(list);
 
-	WriteToFile(strText);
+	CString* pstrLog = new CString(strText);
+	PostThreadMessage(m_ThreadId, WM_DIPLAY_LOG, reinterpret_cast<WPARAM>(pstrLog), 0);
 
-	if(m_pDM2P)
+// 	WriteToFile(strText);
+// 
+// 	if(m_pDM2P)
+// 	{
+// 		m_pDM2P->DM2P_DisplayMessage(strText);
+// 	}
+}
+// #3417 LYWCF AOI Review �쟾�꽕鍮� Log Process媛쒖꽑 ADD END
+
+// #3417 LYWCF AOI Review �쟾�꽕鍮� Log Process媛쒖꽑 ADD START
+void CDisplayMessage::ThreadDisplayMessage(const CString& strMessage)
+{
+	WriteToFile(strMessage);
+
+	if (m_pDM2P)
 	{
-		m_pDM2P->DM2P_DisplayMessage(strText);
+		m_pDM2P->DM2P_DisplayMessage(strMessage);
 	}
 }
 
@@ -82,7 +110,7 @@
 {
 	if(m_pFileLog == NULL)	return FALSE;
 
-	EnterCriticalSection(&m_csLog);
+	//EnterCriticalSection(&m_csLog);
 
 	CTime	time = CTime::GetCurrentTime();
 	CString	strTimeStamp = _T("");
@@ -107,10 +135,28 @@
 		m_pFileLog->Close();
 	}
 
-	LeaveCriticalSection(&m_csLog);
+	//LeaveCriticalSection(&m_csLog);
 
 	return TRUE;
 }
 
+DWORD RunThreadDisplayLog(LPVOID param)
+{
+	MSG msg;
+	while (GetMessage(&msg, NULL, 0, 0))
+	{
+		CString* pstrLog = reinterpret_cast<CString*>(msg.wParam);
+		switch (msg.message)
+		{
+		case WM_DIPLAY_LOG:
+			
+			g_pLog->ThreadDisplayMessage(*pstrLog);
+			break;
 
-
+		default:
+			break;
+		}
+	}
+	return 0;
+}
+// #3417 LYWCF AOI Review �쟾�꽕鍮� Log Process媛쒖꽑 ADD END
diff --git a/ReviewSystem/ReviewSystem/DisplayMessage.h b/ReviewSystem/ReviewSystem/DisplayMessage.h
index 5f2af9b..4c5800c 100644
--- a/ReviewSystem/ReviewSystem/DisplayMessage.h
+++ b/ReviewSystem/ReviewSystem/DisplayMessage.h
@@ -2,12 +2,16 @@
 
 #include "CHEdgeTriangle/Singleton.h"
 
+#define WM_DIPLAY_LOG          WM_USER + 1000
+
 interface IDisplayMessage2Parent
 {
 public:
 	virtual void	DM2P_DisplayMessage(const CString& strMessage) = 0;
 	virtual void	DM2P_DisplayMessage(const TCHAR* lpstrFormat, ...) = 0;
 };
+
+DWORD RunThreadDisplayLog(LPVOID param);
 
 class CDisplayMessage : public Singleton<CDisplayMessage>
 {
@@ -22,6 +26,7 @@
 	BOOL	WriteToFile(const CString& strMessage);
 	void	DisplayMessage(const CString& strMessage);
 	void	DisplayMessage(const TCHAR* lpstrFormat, ...);
+	void	ThreadDisplayMessage(const CString & strMessage);
 
 public:
 	CTime						m_TimeLogFile;
@@ -30,6 +35,7 @@
 	CString						m_strLogFile;
 	IDisplayMessage2Parent*		m_pDM2P;
 	CRITICAL_SECTION			m_csLog;
+	DWORD						m_ThreadId;
 };
 
 #define g_pLog	CDisplayMessage::GetSingletonPtr()
\ No newline at end of file
diff --git a/ReviewSystem/ReviewSystem/DlgLog.cpp b/ReviewSystem/ReviewSystem/DlgLog.cpp
index f93a01a..53068df 100644
--- a/ReviewSystem/ReviewSystem/DlgLog.cpp
+++ b/ReviewSystem/ReviewSystem/DlgLog.cpp
@@ -23,7 +23,20 @@
 void CDlgLog::DoDataExchange(CDataExchange* pDX)
 {
 	CDialog::DoDataExchange(pDX);
-	DDX_Control(pDX, IDC_LIST_LOG, m_ctrlLogListBox);
+	DDX_Control(pDX, IDC_LIST_LOG, m_ctrlLogList);
+}
+
+BOOL CDlgLog::OnInitDialog()
+{
+	CDialog::OnInitDialog();
+
+	// TODO:  �뿬湲곗뿉 異붽� 珥덇린�솕 �옉�뾽�쓣 異붽��빀�땲�떎.
+	m_ctrlLogList.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
+	m_ctrlLogList.InsertColumn(0, _T("�떆媛�"), LVCFMT_CENTER, 150);
+	m_ctrlLogList.InsertColumn(1, _T("�궡�슜"), LVCFMT_LEFT, 690);
+
+	return TRUE;  // return TRUE unless you set the focus to a control
+				  // �삁�쇅: OCX �냽�꽦 �럹�씠吏��뒗 FALSE瑜� 諛섑솚�빐�빞 �빀�땲�떎.
 }
 
 
@@ -52,9 +65,9 @@
 {
 	CDialog::OnSize(nType, cx, cy);
 
-	if (m_ctrlLogListBox.GetSafeHwnd())
+	if (m_ctrlLogList.GetSafeHwnd())
 	{
-		m_ctrlLogListBox.SetWindowPos(NULL, 0, 0, cx, cy, SWP_NOZORDER);
+		m_ctrlLogList.SetWindowPos(NULL, 0, 0, cx, cy, SWP_NOZORDER);
 	}
 
 	// TODO: �뿬湲곗뿉 硫붿떆吏� 泥섎━湲� 肄붾뱶瑜� 異붽��빀�땲�떎.
@@ -62,22 +75,23 @@
 
 void CDlgLog::DisplayMessage(const CString& strMessage)
 {
-	int nCount;
 	CTime time;
-	CString strStamp, strLog;
+	CString strStamp;
 
-	nCount = m_ctrlLogListBox.GetCount();
+	if (m_ctrlLogList.GetItemCount() > 100)
+		m_ctrlLogList.DeleteItem(0);
 
-	if (nCount % MAX_PRINT_COUNT == 0)
-	{
-		m_ctrlLogListBox.ResetContent();
-	}
+	//if (nCount % MAX_PRINT_COUNT == 0)
+	//{
+	//	m_ctrlLogList.ResetContent();
+	//}
 
 	SYSTEMTIME   currentTime;
 	::GetLocalTime(&currentTime);
 	time = CTime::GetCurrentTime();
-	strStamp.Format(_T("[%02d:%02d:%02d]"), time.GetHour(), time.GetMinute(), time.GetSecond());
-	strLog.Format(_T("%s %s"), strStamp, strMessage);
-	m_ctrlLogListBox.AddString(strLog);
-	m_ctrlLogListBox.SetCurSel(m_ctrlLogListBox.GetCount()-1);
-}
\ No newline at end of file
+	strStamp.Format(_T("[%02d:%02d:%02d:%02d:%02d:%02d]"), time.GetYear(), time.GetMonth(), time.GetDay(), time.GetHour(), time.GetMinute(), time.GetSecond());
+
+	int nRow = m_ctrlLogList.InsertItem(m_ctrlLogList.GetItemCount(), strStamp);
+	m_ctrlLogList.SetItemText(nRow, 1, strMessage);
+	m_ctrlLogList.EnsureVisible(nRow, FALSE);
+}
diff --git a/ReviewSystem/ReviewSystem/DlgLog.h b/ReviewSystem/ReviewSystem/DlgLog.h
index e8e0eef..b0d8f47 100644
--- a/ReviewSystem/ReviewSystem/DlgLog.h
+++ b/ReviewSystem/ReviewSystem/DlgLog.h
@@ -22,6 +22,7 @@
 
 protected:
 	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 吏��썝�엯�땲�떎.
+	virtual BOOL OnInitDialog();
 
 	DECLARE_MESSAGE_MAP()
 public:
@@ -30,5 +31,6 @@
 	afx_msg void OnSize(UINT nType, int cx, int cy);
 
 protected:
-	CListBox m_ctrlLogListBox;
+	CListCtrl m_ctrlLogList;
+
 };
diff --git a/ReviewSystem/ReviewSystem/ReviewSystem.rc b/ReviewSystem/ReviewSystem/ReviewSystem.rc
index 4fbafb4..458c5c9 100644
--- a/ReviewSystem/ReviewSystem/ReviewSystem.rc
+++ b/ReviewSystem/ReviewSystem/ReviewSystem.rc
@@ -278,7 +278,7 @@
 STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD
 FONT 9, "MS Shell Dlg", 0, 0, 0x0
 BEGIN
-    LISTBOX         IDC_LIST_LOG,5,5,48,32,LBS_NOINTEGRALHEIGHT | LBS_DISABLENOSCROLL | WS_VSCROLL | WS_TABSTOP
+    CONTROL         "",IDC_LIST_LOG,"SysListView32",LVS_REPORT | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP,5,5,60,50
 END
 
 IDD_DLG_DEFECT_FILTER DIALOGEX 0, 0, 366, 409
@@ -1389,6 +1389,11 @@
     0
 END
 
+IDD_DLG_TAB_LOG AFX_DIALOG_LAYOUT
+BEGIN
+    0
+END
+
 
 /////////////////////////////////////////////////////////////////////////////
 //
diff --git a/ReviewSystem/ReviewSystem/resource.h b/ReviewSystem/ReviewSystem/resource.h
index cd5dbda..5ff1b94 100644
--- a/ReviewSystem/ReviewSystem/resource.h
+++ b/ReviewSystem/ReviewSystem/resource.h
@@ -299,7 +299,6 @@
 #define IDC_EDIT_REVIEW_PANEL_POS_Y4    1109
 #define IDC_BT_CAMERA_GRAB              1109
 #define IDC_BUTTION_TARGET_POS          1109
-//#define IDC_BUTTON_PROGRAMEXIT          1109
 #define IDC_GRID_ALIGN_INFO             1110
 #define IDC_EDIT_UPDATE_NOTE            1110
 #define IDC_BUTTON4                     1110
@@ -398,7 +397,7 @@
 // 
 #ifdef APSTUDIO_INVOKED
 #ifndef APSTUDIO_READONLY_SYMBOLS
-#define _APS_NEXT_RESOURCE_VALUE        380
+#define _APS_NEXT_RESOURCE_VALUE        381
 #define _APS_NEXT_COMMAND_VALUE         32775
 #define _APS_NEXT_CONTROL_VALUE         1175
 #define _APS_NEXT_SYMED_VALUE           346

--
Gitblit v1.9.3