From b6e370081c3692bdfcdede5106d42734d2c6ef2f Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期一, 13 一月 2025 10:58:48 +0800
Subject: [PATCH] 1.增加输入框超范围时的黄色提示;

---
 SourceCode/Bond/BoounionPLC/CBaseDlg.h          |    4 ++
 SourceCode/Bond/BoounionPLC/BoounionPLC.rc      |    0 
 SourceCode/Bond/BoounionPLC/Resource.h          |    0 
 SourceCode/Bond/BoounionPLC/CBaseDlg.cpp        |    9 ++++
 SourceCode/Bond/BoounionPLC/AxisSettingsDlg.cpp |   88 ++++++++++++++++++++++++++++++++++++++++++-
 SourceCode/Bond/BoounionPLC/AxisSettingsDlg.h   |   14 +++++++
 6 files changed, 112 insertions(+), 3 deletions(-)

diff --git a/SourceCode/Bond/BoounionPLC/AxisSettingsDlg.cpp b/SourceCode/Bond/BoounionPLC/AxisSettingsDlg.cpp
index ae81f43..9b58189 100644
--- a/SourceCode/Bond/BoounionPLC/AxisSettingsDlg.cpp
+++ b/SourceCode/Bond/BoounionPLC/AxisSettingsDlg.cpp
@@ -16,6 +16,7 @@
 
 #define TIMER_INIT					1
 #define TIMER_READ_PLC_DATA			2
+#define TIMER_HIDE_TIP				3
 
 #define ID_MSG_UPDATA_DATA_TO_UI	WM_USER + 101
 
@@ -62,6 +63,10 @@
 	
 	m_nBtnsFlashState6 = 0;
 	m_nBtnsFlashState8 = 0;
+	m_crTipBack = RGB(255, 127, 39);
+	m_crTipText = RGB(228, 228, 228);
+	m_hbrTip = CreateSolidBrush(m_crTipBack);
+	m_hTipFont = nullptr;
 }
 
 CAxisSettingsDlg::~CAxisSettingsDlg()
@@ -82,6 +87,18 @@
 		delete m_pAxisManager;
 		m_pAxisManager = nullptr;
 	}
+	::DeleteObject(m_hbrTip);
+	if (m_hTipFont != nullptr) {
+		::DeleteObject(m_hTipFont);
+	}
+}
+
+BOOL CAxisSettingsDlg::PreAdjustControl(CWnd* pWnd)
+{
+	int nCtrlID = pWnd->GetDlgCtrlID();
+	if (nCtrlID == IDC_LABEL_TIP) return FALSE;
+
+	return TRUE;
 }
 
 void CAxisSettingsDlg::DoDataExchange(CDataExchange* pDX)
@@ -759,6 +776,8 @@
 	ON_WM_SIZE()
 	ON_WM_TIMER()
 	ON_WM_CLOSE()
+	ON_WM_CTLCOLOR()
+	ON_EN_KILLFOCUS(IDC_EDIT_AXIS_MODITFY_MICROMENTUM, &CAxisSettingsDlg::OnEnKillfocusEditAxisModitfyMicromentum)
 END_MESSAGE_MAP()
 
 
@@ -1011,8 +1030,17 @@
 void CAxisSettingsDlg::OnSize(UINT nType, int cx, int cy)
 {
 	CBaseDlg::OnSize(nType, cx, cy);
-
+	if (GetDlgItem(IDC_LABEL_TIP) == nullptr) return;
 	// TODO: 鍦ㄦ澶勬坊鍔犳秷鎭鐞嗙▼搴忎唬鐮�
+
+	CWnd* pItem;
+	CRect rcClient;
+	GetClientRect(&rcClient);
+
+	pItem = GetDlgItem(IDC_LABEL_TIP);
+	pItem->MoveWindow(0, 0, rcClient.Width(), 36);
+
+
 	// 鍔ㄦ�佽皟鏁村悇涓� CBLLabel 鐨勫瓧浣撳ぇ灏�
 	for (auto pLabel : m_pBlLabels) {
 		AdjustLabelFont(*pLabel);
@@ -1061,13 +1089,11 @@
 
 void CAxisSettingsDlg::OnBnClickedButtonAxisAnchorPointGroup2()
 {
-	// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
 	SwitchToPage(2);
 }
 
 void CAxisSettingsDlg::OnBnClickedButtonAxisAnchorPointGroup3()
 {
-	// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
 	SwitchToPage(3);
 }
 
@@ -1370,6 +1396,10 @@
 
 		ReadPLCDataToUI(nAxisId);
 	}	
+	else if (TIMER_HIDE_TIP == nIDEvent) {
+		KillTimer(TIMER_HIDE_TIP);
+		HideTip();
+	}
 
 	CBaseDlg::OnTimer(nIDEvent);
 }
@@ -1381,3 +1411,55 @@
 
 	CBaseDlg::OnClose();
 }
+
+
+HBRUSH CAxisSettingsDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
+{
+	HBRUSH hbr = CBaseDlg::OnCtlColor(pDC, pWnd, nCtlColor);
+
+	int nCtrlID = pWnd->GetDlgCtrlID();
+	if (nCtrlID == IDC_LABEL_TIP) {
+		pDC->SetTextColor(m_crTipText);
+		pDC->SetBkColor(m_crTipBack);
+		if (m_hTipFont == nullptr) {
+			HFONT hFontDefault = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
+			CFont* pFont = CFont::FromHandle(hFontDefault);
+			LOGFONT lf;
+			pFont->GetLogFont(&lf);
+			lf.lfHeight -= 8;
+			m_hTipFont = ::CreateFontIndirect(&lf);
+			::SelectObject(pDC->m_hDC, m_hTipFont);
+		}
+
+
+		return m_hbrTip;
+	}
+
+
+	return hbr;
+}
+
+void CAxisSettingsDlg::ShowTipText(const char* pszText, float sec)
+{
+	CString strText;
+	strText.Format(_T(" * %s"), pszText);
+	SetDlgItemText(IDC_LABEL_TIP, strText);
+	GetDlgItem(IDC_LABEL_TIP)->ShowWindow(SW_SHOW);
+
+	SetTimer(TIMER_HIDE_TIP, (int)(sec * 1000.0), nullptr);
+}
+
+void CAxisSettingsDlg::HideTip()
+{
+	GetDlgItem(IDC_LABEL_TIP)->ShowWindow(SW_HIDE);
+}
+
+void CAxisSettingsDlg::OnEnKillfocusEditAxisModitfyMicromentum()
+{
+	CString strText;
+	GetDlgItemText(IDC_EDIT_AXIS_MODITFY_MICROMENTUM, strText);
+	double value = atof(strText);
+	if (value < 0.0 || value > 0.1) {
+		ShowTipText("寰姩閲忓�煎繀椤诲湪0.0 ~ 0.1涔嬮棿", 5);
+	}
+}
diff --git a/SourceCode/Bond/BoounionPLC/AxisSettingsDlg.h b/SourceCode/Bond/BoounionPLC/AxisSettingsDlg.h
index 0f0d198..240812f 100644
--- a/SourceCode/Bond/BoounionPLC/AxisSettingsDlg.h
+++ b/SourceCode/Bond/BoounionPLC/AxisSettingsDlg.h
@@ -72,6 +72,11 @@
 	CAxisSettingsDlg(CWnd* pParent = nullptr);   // 鏍囧噯鏋勯�犲嚱鏁�
 	virtual ~CAxisSettingsDlg();
 
+
+private:
+	virtual BOOL PreAdjustControl(CWnd* pWnd);
+
+
 // 瀵硅瘽妗嗘暟鎹�
 #ifdef AFX_DESIGN_TIME
 	enum { IDD = IDD_DIALOG_AXIS_SETTINGS };
@@ -98,9 +103,15 @@
 	void WriteAxisDataToPLC(int nAxisId);
 	void HandleAxisOperation(AxisOperationType eOpType, bool bPressed);
 	void ReadPLCDataToUI(int nAxisId);
+	void ShowTipText(const char* pszText, float sec);
+	void HideTip();
 
 private:
 	CPLC* m_pPLC;
+	HBRUSH m_hbrTip;
+	HFONT m_hTipFont;
+	COLORREF m_crTipBack;
+	COLORREF m_crTipText;
 
 	// 褰撳墠閫変腑鐨勫畾浣嶉〉闈㈢储寮�
 	int m_currentPage;
@@ -161,4 +172,7 @@
 	afx_msg void OnTimer(UINT_PTR nIDEvent);
 	afx_msg void OnClose();
 	DECLARE_MESSAGE_MAP()
+public:
+	afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
+	afx_msg void OnEnKillfocusEditAxisModitfyMicromentum();
 };
diff --git a/SourceCode/Bond/BoounionPLC/BoounionPLC.rc b/SourceCode/Bond/BoounionPLC/BoounionPLC.rc
index dfa53da..82b9000 100644
--- a/SourceCode/Bond/BoounionPLC/BoounionPLC.rc
+++ b/SourceCode/Bond/BoounionPLC/BoounionPLC.rc
Binary files differ
diff --git a/SourceCode/Bond/BoounionPLC/CBaseDlg.cpp b/SourceCode/Bond/BoounionPLC/CBaseDlg.cpp
index 1242983..7d0a291 100644
--- a/SourceCode/Bond/BoounionPLC/CBaseDlg.cpp
+++ b/SourceCode/Bond/BoounionPLC/CBaseDlg.cpp
@@ -34,6 +34,11 @@
 	DeleteObject(m_hBrush);
 }
 
+BOOL CBaseDlg::PreAdjustControl(CWnd* pWnd)
+{
+	return TRUE;
+}
+
 void CBaseDlg::SwitchTheme(ThemeType enThemeType)
 {
 	// 使用 map 来根据 themeType 查找主题
@@ -176,6 +181,10 @@
 	m_bResizing = true;
 	CWnd* pWnd = GetWindow(GW_CHILD);
 	while (pWnd) {
+		if (!PreAdjustControl(pWnd)) {
+			pWnd = pWnd->GetNextWindow();
+			continue;
+		}
 		int nCtrlID = pWnd->GetDlgCtrlID();
 		if (nCtrlID != -1 && m_mapCtrlLayouts.find(nCtrlID) != m_mapCtrlLayouts.end()) {
 			CRect originalRect = m_mapCtrlLayouts[nCtrlID];
diff --git a/SourceCode/Bond/BoounionPLC/CBaseDlg.h b/SourceCode/Bond/BoounionPLC/CBaseDlg.h
index c879bcf..dc762f3 100644
--- a/SourceCode/Bond/BoounionPLC/CBaseDlg.h
+++ b/SourceCode/Bond/BoounionPLC/CBaseDlg.h
@@ -23,6 +23,10 @@
 	CBaseDlg(UINT nID, CWnd* pPage);			// 标准构造函数
 	virtual ~CBaseDlg();						// 析构函数
 
+
+public:
+	virtual BOOL PreAdjustControl(CWnd* pWnd);
+
 	// 主题管理
 	void SwitchTheme(ThemeType enThemeType);			// 切换主题
 
diff --git a/SourceCode/Bond/BoounionPLC/Resource.h b/SourceCode/Bond/BoounionPLC/Resource.h
index aa5f648..9dfbd5d 100644
--- a/SourceCode/Bond/BoounionPLC/Resource.h
+++ b/SourceCode/Bond/BoounionPLC/Resource.h
Binary files differ

--
Gitblit v1.9.3