From fc8a07f476648f82abf9934483b04cfee0161e4e Mon Sep 17 00:00:00 2001
From: LAPTOP-T815PCOQ\25526 <mr.liuyang@126.com>
Date: 星期四, 28 十一月 2024 10:44:27 +0800
Subject: [PATCH] 1.扩展静态文本实现回调函数点击事件 2.模拟监听PLC

---
 SourceCode/Bond/BondEq/View/SystemLogManagerDlg.cpp |  172 +++++++++++++++++++++++++++++++++-----------------------
 1 files changed, 101 insertions(+), 71 deletions(-)

diff --git a/SourceCode/Bond/BondEq/View/SystemLogManagerDlg.cpp b/SourceCode/Bond/BondEq/View/SystemLogManagerDlg.cpp
index 004e2d8..f5603fb 100644
--- a/SourceCode/Bond/BondEq/View/SystemLogManagerDlg.cpp
+++ b/SourceCode/Bond/BondEq/View/SystemLogManagerDlg.cpp
@@ -14,7 +14,8 @@
 CSystemLogManagerDlg::CSystemLogManagerDlg(CWnd* pParent /*=nullptr*/)
 	: CDialogEx(IDD_DIALOG_SYSTEM_LOG_MANAGER, pParent)
 {
-
+	m_nInitialWidth = 0;
+	m_nInitialHeight = 0;
 }
 
 CSystemLogManagerDlg::~CSystemLogManagerDlg()
@@ -70,11 +71,11 @@
 	m_listLogs.SetItemText(nRowIdx, nColIdx++, _T("No."));
 	m_listLogs.SetColumnWidth(nColIdx, 10);
 	m_listLogs.SetItemText(nRowIdx, nColIdx++, _T("绫诲瀷"));
-	m_listLogs.SetColumnWidth(nColIdx, 200);
+	m_listLogs.SetColumnWidth(nColIdx, 100);
 	m_listLogs.SetItemText(nRowIdx, nColIdx++, _T("浜嬩欢"));
 	m_listLogs.SetColumnWidth(nColIdx, 30);
 	m_listLogs.SetItemText(nRowIdx, nColIdx++, _T("鐢ㄦ埛"));
-	m_listLogs.SetColumnWidth(nColIdx, 70);
+	m_listLogs.SetColumnWidth(nColIdx, 50);
 	m_listLogs.SetItemText(nRowIdx, nColIdx++, _T("鏃堕棿"));
 
 	// 鍒涘缓 20 琛岀┖鐧芥暟鎹
@@ -152,11 +153,30 @@
 		}
 	}
 
-	m_listLogs.Invalidate();
-	m_listLogs.UpdateWindow();
 	m_listLogs.ExpandColumnsToFit(FALSE);
 	m_listLogs.ExpandLastColumn();
+	m_listLogs.Invalidate();
+	m_listLogs.UpdateWindow();
+
 	UpdatePageInfo();
+}
+
+CFont* CSystemLogManagerDlg::GetOrCreateFont(int nFontSize)
+{
+	auto it = m_mapFonts.find(nFontSize);
+	if (it != m_mapFonts.end()) {
+		return it->second;
+	}
+
+	CFont* font = new CFont();
+	LOGFONT logFont = { 0 };
+	_tcscpy_s(logFont.lfFaceName, _T("Segoe UI"));
+	logFont.lfHeight = -nFontSize;
+	logFont.lfQuality = CLEARTYPE_QUALITY;
+	font->CreateFontIndirect(&logFont);
+	m_mapFonts[nFontSize] = font;
+
+	return font;
 }
 
 void CSystemLogManagerDlg::UpdatePageInfo()
@@ -169,23 +189,7 @@
 
 void CSystemLogManagerDlg::SetDefaultFont()
 {
-	CFont* defaultFont = nullptr;
-
-	// 濡傛灉瀛椾綋绠$悊瀹瑰櫒涓湁榛樿澶у皬锛堝 12锛夌殑瀛椾綋锛岀洿鎺ヤ娇鐢�
-	auto it = m_mapFonts.find(12);
-	if (it != m_mapFonts.end()) {
-		defaultFont = it->second;
-	}
-	else {
-		// 鍒涘缓榛樿瀛椾綋
-		defaultFont = new CFont();
-		LOGFONT logFont = { 0 };
-		_tcscpy_s(logFont.lfFaceName, _T("Segoe UI"));
-		logFont.lfHeight = -12;
-		logFont.lfQuality = CLEARTYPE_QUALITY;
-		defaultFont->CreateFontIndirect(&logFont);
-		m_mapFonts[12] = defaultFont; // 瀛樺偍鍒板瓧浣撶鐞嗗鍣�
-	}
+	CFont* defaultFont = GetOrCreateFont(12);
 
 	// 閬嶅巻鎵�鏈夋帶浠讹紝搴旂敤榛樿瀛椾綋
 	CWnd* pWnd = GetWindow(GW_CHILD);
@@ -203,41 +207,40 @@
 	}
 }
 
-void CSystemLogManagerDlg::AdjustControls(int nWidth, int nHeight)
+void CSystemLogManagerDlg::AdjustControls(float dScaleX, float dScaleY)
 {
 	CWnd* pWnd = GetWindow(GW_CHILD);
 	while (pWnd) {
-		UINT nCtrlID = pWnd->GetDlgCtrlID();
+		int nCtrlID = pWnd->GetDlgCtrlID();
+		if (nCtrlID != -1 && m_mapCtrlLayouts.find(nCtrlID) != m_mapCtrlLayouts.end())
+		{
+			CRect originalRect = m_mapCtrlLayouts[nCtrlID];
+			CRect newRect(
+				static_cast<int>(originalRect.left * dScaleX),
+				static_cast<int>(originalRect.top * dScaleY),
+				static_cast<int>(originalRect.right * dScaleX),
+				static_cast<int>(originalRect.bottom * dScaleY));
 
-		CRect ctrlRect;
-		pWnd->GetWindowRect(&ctrlRect);
-		ScreenToClient(&ctrlRect);
+			TCHAR szClassName[256];
+			GetClassName(pWnd->m_hWnd, szClassName, sizeof(szClassName));
 
-		// 璁$畻鎺т欢鐨勬柊浣嶇疆鍜屽ぇ灏忥紝鎸夋瘮渚嬭皟鏁�
-		int newX = (int)(ctrlRect.left * (nWidth / (float)m_nInitialWidth));
-		int newY = (int)(ctrlRect.top * (nHeight / (float)m_nInitialHeight));
-		int newWidth = (int)(ctrlRect.Width() * (nWidth / (float)m_nInitialWidth));
-		int newHeight = (int)(ctrlRect.Height() * (nHeight / (float)m_nInitialHeight));
+			if (_tcsicmp(szClassName, _T("ComboBox")) == 0) {
+				CComboBox* pComboBox = (CComboBox*)pWnd;
+				pComboBox->SetItemHeight(-1, newRect.Height());  // -1 琛ㄧず鎵�鏈夐」鐨勯珮搴�
+			}
 
-		TCHAR szClassName[256];
-		GetClassName(pWnd->m_hWnd, szClassName, sizeof(szClassName));
+			if (_tcsicmp(szClassName, _T("MFCGridCtrl")) == 0) {
+				CGridCtrl* pGridCtrl = (CGridCtrl*)pWnd;
+				pGridCtrl->SetDefCellHeight(newRect.Height() / 21);
+				pGridCtrl->ExpandColumnsToFit(TRUE);
+				pGridCtrl->ExpandLastColumn();
+				pGridCtrl->Invalidate();
+				pGridCtrl->UpdateWindow();
+			}
 
-		if (_tcsicmp(szClassName, _T("ComboBox")) == 0) {
-			CComboBox* pComboBox = (CComboBox*)pWnd;
-			pComboBox->SetItemHeight(-1, nHeight);  // -1 琛ㄧず鎵�鏈夐」鐨勯珮搴�
+			pWnd->MoveWindow(&newRect);
+			AdjustControlFont(pWnd, newRect.Width(), newRect.Height());
 		}
-
-		if (_tcsicmp(szClassName, _T("MFCGridCtrl")) == 0) {
-			CGridCtrl* pGridCtrl = (CGridCtrl*)pWnd;
-			pGridCtrl->SetDefCellHeight(newHeight / 21);
-			pGridCtrl->ExpandColumnsToFit(TRUE);
-			pGridCtrl->Invalidate();
-		}
-
-		pWnd->MoveWindow(newX, newY, newWidth, newHeight);
-		AdjustControlFont(pWnd, newWidth, newHeight);
-
-		// 鑾峰彇涓嬩竴涓帶浠�
 		pWnd = pWnd->GetNextWindow();
 	}
 }
@@ -256,23 +259,10 @@
 	int fontSize = nHeight / 2;
 	if (fontSize < 8) fontSize = 8;
 
-	// 妫�鏌ュ瓧浣撴槸鍚﹀凡缁忓瓨鍦�
-	auto it = m_mapFonts.find(fontSize);
-	if (it == m_mapFonts.end()) {
-		// 鍔ㄦ�佸垱寤烘柊瀛椾綋
-		CFont* newFont = new CFont();
-		LOGFONT logFont = { 0 };
-		_tcscpy_s(logFont.lfFaceName, _T("Segoe UI"));
-		logFont.lfHeight = -fontSize;
-		logFont.lfQuality = CLEARTYPE_QUALITY; // 鍚敤 ClearType 鎶楅敮榻�
-		newFont->CreateFontIndirect(&logFont);
+	// 鑾峰彇鎴栧垱寤哄瓧浣�
+	CFont* pFont = GetOrCreateFont(fontSize);
 
-		// 瀛樺偍鍒板瓧浣撶鐞嗗鍣ㄤ腑
-		m_mapFonts[fontSize] = newFont;
-		it = m_mapFonts.find(fontSize);
-	}
-
-	pWnd->SetFont(it->second);
+	pWnd->SetFont(pFont);
 	pWnd->Invalidate(); // 鍒锋柊鎺т欢鏄剧ず
 }
 
@@ -302,6 +292,7 @@
 	ON_CBN_SELCHANGE(IDC_COMBO_TYPE, &CSystemLogManagerDlg::OnSelchangeComboType)
 	ON_CBN_SELCHANGE(IDC_COMBO_USER, &CSystemLogManagerDlg::OnSelchangeComboUser)
 	ON_WM_SIZE()
+	ON_WM_GETMINMAXINFO()
 END_MESSAGE_MAP()
 
 
@@ -314,9 +305,6 @@
 
 	// TODO:  鍦ㄦ娣诲姞棰濆鐨勫垵濮嬪寲
 	SetWindowText(_T("绯荤粺杩愯鏃ュ織"));
-
-	// 璁剧疆榛樿瀛椾綋
-	SetDefaultFont();
 
 	m_nCurrentPage = 1;  // 浠庣涓�椤靛紑濮�
 	m_nTotalPages = 1;   // 榛樿鎬婚〉鏁颁负 1
@@ -347,6 +335,34 @@
 	m_nInitialWidth = clientRect.Width();
 	m_nInitialHeight = clientRect.Height();
 
+	// 鍒濆鍖栭粯璁ゅ瓧浣�
+	CFont* pDefaultFont = GetOrCreateFont(12);
+
+	// 閬嶅巻鎵�鏈夊瓙鎺т欢锛岃褰曞垵濮嬩綅缃苟璁剧疆榛樿瀛椾綋
+	CWnd* pWnd = GetWindow(GW_CHILD);
+	while (pWnd) {
+		int nCtrlID = pWnd->GetDlgCtrlID();
+		if (nCtrlID != -1) {
+			// 璁板綍鎺т欢鍒濆甯冨眬
+			CRect ctrlRect;
+			pWnd->GetWindowRect(&ctrlRect);
+			ScreenToClient(&ctrlRect);
+			m_mapCtrlLayouts[nCtrlID] = ctrlRect;
+
+			// 璺宠繃鐗规畩鎺т欢锛堝 MFCGridCtrl锛�
+			TCHAR szClassName[256];
+			GetClassName(pWnd->m_hWnd, szClassName, sizeof(szClassName));
+			if (_tcsicmp(szClassName, _T("MFCGridCtrl")) == 0) {
+				pWnd = pWnd->GetNextWindow();
+				continue;
+			}
+
+			// 璁剧疆榛樿瀛椾綋
+			pWnd->SetFont(pDefaultFont);
+		}
+		pWnd = pWnd->GetNextWindow();
+	}
+
 	GetWindowRect(&dlgRect);
 	int dlgWidth = dlgRect.Width() * 2;
 	int dlgHeight = dlgRect.Height() * 2;
@@ -375,11 +391,25 @@
 	CDialogEx::OnSize(nType, cx, cy);
 
 	// TODO: 鍦ㄦ澶勬坊鍔犳秷鎭鐞嗙▼搴忎唬鐮�
-	CRect rect;
-	GetClientRect(&rect);
+	if (nType == SIZE_MINIMIZED || m_mapCtrlLayouts.empty()) {
+		return;
+	}
+
+	float dScaleX = static_cast<float>(cx) / m_nInitialWidth;
+	float dScaleY = static_cast<float>(cy) / m_nInitialHeight;
 
 	// 閬嶅巻瀵硅瘽妗嗕腑鐨勬墍鏈夋帶浠�
-	AdjustControls(rect.Width(), rect.Height());
+	AdjustControls(dScaleX, dScaleY);
+}
+
+
+void CSystemLogManagerDlg::OnGetMinMaxInfo(MINMAXINFO* lpMMI)
+{
+	// TODO: 鍦ㄦ娣诲姞娑堟伅澶勭悊绋嬪簭浠g爜鍜�/鎴栬皟鐢ㄩ粯璁ゅ��
+	lpMMI->ptMinTrackSize.x = 400; // 鏈�灏忓搴�
+	lpMMI->ptMinTrackSize.y = 300; // 鏈�灏忛珮搴�
+
+	CDialogEx::OnGetMinMaxInfo(lpMMI);
 }
 
 

--
Gitblit v1.9.3