From 158805c18a8e705f8ed75650a2593b80aea18ccd Mon Sep 17 00:00:00 2001
From: LAPTOP-T815PCOQ\25526 <mr.liuyang@126.com>
Date: 星期四, 28 十一月 2024 09:10:27 +0800
Subject: [PATCH] 1.使用静态文本控件的扩展,把状态设置背景颜色

---
 SourceCode/Bond/BondEq/View/IOMonitoringDlg.cpp |   53 +++++++++++++++++++++++++----------------------------
 SourceCode/Bond/BondEq/View/IOMonitoringDlg.h   |    5 +++--
 2 files changed, 28 insertions(+), 30 deletions(-)

diff --git a/SourceCode/Bond/BondEq/View/IOMonitoringDlg.cpp b/SourceCode/Bond/BondEq/View/IOMonitoringDlg.cpp
index 62a2d2c..2897dfb 100644
--- a/SourceCode/Bond/BondEq/View/IOMonitoringDlg.cpp
+++ b/SourceCode/Bond/BondEq/View/IOMonitoringDlg.cpp
@@ -88,8 +88,7 @@
 	CWnd* pWnd = GetWindow(GW_CHILD);
 	while (pWnd) {
 		int nCtrlID = pWnd->GetDlgCtrlID();
-		if (nCtrlID != -1 && m_mapCtrlLayouts.find(nCtrlID) != m_mapCtrlLayouts.end())
-		{
+		if (nCtrlID != -1 && m_mapCtrlLayouts.find(nCtrlID) != m_mapCtrlLayouts.end()) {
 			CRect originalRect = m_mapCtrlLayouts[nCtrlID];
 			CRect newRect(
 				static_cast<int>(originalRect.left * dScaleX),
@@ -162,50 +161,49 @@
 	int colWidthLarge = availableWidth * 4 / 14;		// 澶у搴﹀垪姣斾緥
 	int groupWidth = colWidthSmall * 2 + colWidthLarge; // 姣忕粍鎬诲搴�
 
-	for (int i = 0; i < m_nRowsPerPage; ++i)
-	{
+	for (int i = 0; i < m_nRowsPerPage; ++i) {
 		// 姣忎竴琛岀殑璧峰 Y 鍧愭爣
 		int y = topMargin + i * (rowHeight + verticalSpacing);
 
 		// 鍒涘缓绗� 1 缁� (0, 1, 2)
 		int x = sideMargin; // 浠庡乏杈硅窛寮�濮�
-		CreateStaticControl(x, y, colWidthSmall, rowHeight, _T("OFF"), true);
+		CreateStaticControl(x, y, colWidthSmall, rowHeight, _T("OFF"), true, AlignCenter);
 		x += colWidthSmall;
-		CreateStaticControl(x, y, colWidthSmall, rowHeight, _T("X1000"));
+		CreateStaticControl(x, y, colWidthSmall, rowHeight, _T("X1000"), false, AlignCenter);
 		x += colWidthSmall;
-		CreateStaticControl(x, y, colWidthLarge, rowHeight, _T("鎻忚堪鏂囨湰"), false, true);
+		CreateStaticControl(x, y, colWidthLarge, rowHeight, _T("鎻忚堪鏂囨湰"), false);
 
 		// 绗� 2 缁勮捣濮嬩綅缃紝鍔犱笂缁勯棿璺�
 		x += colWidthLarge + groupSpacing;
 
 		// 鍒涘缓绗� 2 缁� (3, 4, 5)
-		CreateStaticControl(x, y, colWidthSmall, rowHeight, _T("OFF"), true);
+		CreateStaticControl(x, y, colWidthSmall, rowHeight, _T("OFF"), true, AlignCenter);
 		x += colWidthSmall;
-		CreateStaticControl(x, y, colWidthSmall, rowHeight, _T("Y1010"));
+		CreateStaticControl(x, y, colWidthSmall, rowHeight, _T("Y1010"), false, AlignCenter);
 		x += colWidthSmall;
-		CreateStaticControl(x, y, colWidthLarge, rowHeight, _T("鎻忚堪鏂囨湰"), false, true);
+		CreateStaticControl(x, y, colWidthLarge, rowHeight, _T("鎻忚堪鏂囨湰"), false);
 	}
 }
 
-void CIOMonitoringDlg::CreateStaticControl(int x, int y, int width, int height, const CString& text, bool hasBorder, bool alignLeft)
+void CIOMonitoringDlg::CreateStaticControl(int x, int y, int width, int height, const CString& text, bool hasBorder, TextAlign alignment)
 {
+	// 鍒涘缓鍔ㄦ�佹帶浠�
+	CBLLabel* pStatic = new CBLLabel();
 	DWORD style = WS_CHILD | WS_VISIBLE | SS_CENTERIMAGE; // 纭繚鍨傜洿灞呬腑
 	if (hasBorder) {
-		style |= WS_BORDER;		// 娣诲姞杈规
+		style |= WS_BORDER; // 娣诲姞杈规
 	}
-	if (alignLeft) {
-		style |= SS_LEFT;		// 宸﹀榻愭枃鏈�
-	}
-	else {
-		style |= SS_CENTER;		// 灞呬腑鏂囨湰
-	}
-
-	CStatic* pStatic = new CStatic();
 	pStatic->Create(text, style, CRect(x, y, x + width, y + height), this);
 
-	// 鍔ㄦ�佽缃瓧浣撳ぇ灏�
-	CFont* pFont = GetOrCreateFont(height / 3);
+	// 璁剧疆鏂囨湰瀵归綈鏂瑰紡
+	pStatic->SetAlignment(alignment);
+
+	// 璁剧疆鍔ㄦ�佸瓧浣撹皟鏁达紝骞惰缃瓧浣撳ぇ灏忥紙鍔ㄦ�佸瓧浣撲細鏍规嵁鎺т欢澶у皬璋冩暣锛�
+	int nSize = height / 3;
+	CFont* pFont = GetOrCreateFont(nSize);
 	pStatic->SetFont(pFont);
+	pStatic->SetFontSize(nSize);
+	pStatic->SetDynamicFont(TRUE);
 
 	// 瀛樺偍鎺т欢鎸囬拡
 	m_staticControls.push_back(pStatic);
@@ -225,6 +223,7 @@
 			// 鏄剧ず鎺т欢骞惰缃唴瀹�
 			m_staticControls[row * m_nCols + 0]->SetWindowText(_T("OFF"));
 			m_staticControls[row * m_nCols + 0]->ShowWindow(SW_SHOW);
+			m_staticControls[row * m_nCols + 0]->SetBkColor(RGB(255, 0, 0));
 
 			m_staticControls[row * m_nCols + 1]->SetWindowText(CString(data.inputAddress.c_str()));
 			m_staticControls[row * m_nCols + 1]->ShowWindow(SW_SHOW);
@@ -234,6 +233,7 @@
 
 			m_staticControls[row * m_nCols + 3]->SetWindowText(_T("OFF"));
 			m_staticControls[row * m_nCols + 3]->ShowWindow(SW_SHOW);
+			m_staticControls[row * m_nCols + 3]->SetBkColor(RGB(255, 0, 0));
 
 			m_staticControls[row * m_nCols + 4]->SetWindowText(CString(data.outputAddress.c_str()));
 			m_staticControls[row * m_nCols + 4]->ShowWindow(SW_SHOW);
@@ -243,8 +243,7 @@
 		}
 		else {
 			// 闅愯棌杩欎竴琛岀殑鎵�鏈夋帶浠�
-			for (int col = 0; col < m_nCols; ++col)
-			{
+			for (int col = 0; col < m_nCols; ++col) {
 				m_staticControls[row * m_nCols + col]->ShowWindow(SW_HIDE);
 			}
 		}
@@ -255,10 +254,8 @@
 
 void CIOMonitoringDlg::ClearDynamicControls()
 {
-	for (auto* pStatic : m_staticControls)
-	{
-		if (pStatic)
-		{
+	for (auto* pStatic : m_staticControls) {
+		if (pStatic) {
 			pStatic->DestroyWindow();
 			delete pStatic;
 		}
diff --git a/SourceCode/Bond/BondEq/View/IOMonitoringDlg.h b/SourceCode/Bond/BondEq/View/IOMonitoringDlg.h
index 7b34501..10c22c2 100644
--- a/SourceCode/Bond/BondEq/View/IOMonitoringDlg.h
+++ b/SourceCode/Bond/BondEq/View/IOMonitoringDlg.h
@@ -1,6 +1,7 @@
 锘�#pragma once
 #include "afxdialogex.h"
 #include "IOManager.h"
+#include "BLLabel.h"
 
 
 // CIOMonitoringDlg 瀵硅瘽妗�
@@ -27,7 +28,7 @@
 
 	void UpdatePageInfo();			// 鏇存柊鍒嗛〉淇℃伅
 	void CreateDynamicControls();	// 鍔ㄦ�佸垱寤烘帶浠�
-	void CreateStaticControl(int x, int y, int width, int height, const CString& text, bool hasBorder = false, bool alignLeft = false); // 鍒涘缓闈欐�佹帶浠�
+	void CreateStaticControl(int x, int y, int width, int height, const CString& text, bool hasBorder = false, TextAlign alignment = AlignLeft); // 鍒涘缓闈欐�佹帶浠�
 	void DisplayCurrentPage();		// 鏄剧ず褰撳墠椤垫暟鎹�
 	void ClearDynamicControls();	// 娓呴櫎鍔ㄦ�佸垱寤虹殑鎺т欢
 
@@ -45,7 +46,7 @@
 
 private:
 	CStatic m_staticPageNum;
-	std::vector<CStatic*> m_staticControls; // 鍔ㄦ�佸垱寤虹殑闈欐�佹帶浠�
+	std::vector<CBLLabel*> m_staticControls; // 鍔ㄦ�佸垱寤虹殑闈欐�佹帶浠�
 
 protected:
 	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 鏀寔

--
Gitblit v1.9.3