From e15e0d2f9305e71cd160f1ddceab93c7889eab20 Mon Sep 17 00:00:00 2001
From: mrDarker <mr.darker@163.com>
Date: 星期四, 05 六月 2025 17:37:33 +0800
Subject: [PATCH] 1. 解决自定义按钮资源泄露问题 2. 增加Slot点击回调和鼠标悬停/点击高亮效果

---
 SourceCode/Bond/Servo/CRobotTaskDlg.cpp |   37 +++++++++++++++++++++++++++++++++++--
 1 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/SourceCode/Bond/Servo/CRobotTaskDlg.cpp b/SourceCode/Bond/Servo/CRobotTaskDlg.cpp
index 16fd9da..5bfdfaa 100644
--- a/SourceCode/Bond/Servo/CRobotTaskDlg.cpp
+++ b/SourceCode/Bond/Servo/CRobotTaskDlg.cpp
@@ -32,6 +32,7 @@
 	ON_WM_DESTROY()
 	ON_WM_SIZE()
 	ON_WM_ACTIVATE()
+	ON_BN_CLICKED(IDC_BUTTON_ABORT_TASK, &CRobotTaskDlg::OnBnClickedAbortTask)
 END_MESSAGE_MAP()
 
 
@@ -47,6 +48,9 @@
 	GetDlgItem(IDC_LABEL_NO_TASK)->ShowWindow(m_pRobotTask == nullptr ? SW_SHOW : SW_HIDE);
 	GetDlgItem(IDC_LABEL_GET_PUT)->ShowWindow(m_pRobotTask != nullptr ? SW_SHOW : SW_HIDE);
 
+	if (m_btnAbortTask.m_hWnd) {
+		m_btnAbortTask.ShowWindow(m_pRobotTask ? SW_SHOW : SW_HIDE);
+	}
 
 	if (m_pRobotTask != nullptr) {
 		SERVO::CEquipment* pEq1, * pEq2;
@@ -64,6 +68,14 @@
 	CDialogEx::OnInitDialog();
 
 	// TODO:  鍦ㄦ娣诲姞棰濆鐨勫垵濮嬪寲
+	// 鍒涘缓鈥滃仠姝换鍔♀�濇寜閽�
+	m_btnAbortTask.Create(_T("鍋滄浠诲姟"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, CRect(0, 0, 100, 30), this, IDC_BUTTON_ABORT_TASK);
+
+	// 鍔ㄦ�佹寜閽垱寤哄悗璁剧疆瀛椾綋
+	if (m_fontButton.GetSafeHandle() == nullptr) {
+		m_fontButton.CreatePointFont(110, _T("寰蒋闆呴粦")); // 鎴� "Segoe UI"
+	}
+	m_btnAbortTask.SetFont(&m_fontButton);
 
 	return TRUE;  // return TRUE unless you set the focus to a control
 				  // 寮傚父: OCX 灞炴�ч〉搴旇繑鍥� FALSE
@@ -86,6 +98,9 @@
 	CDialogEx::OnDestroy();
 
 	// TODO: 鍦ㄦ澶勬坊鍔犳秷鎭鐞嗙▼搴忎唬鐮�
+	if (m_fontButton.GetSafeHandle()) {
+		::DeleteObject(m_fontButton.Detach());
+	}
 }
 
 void CRobotTaskDlg::OnSize(UINT nType, int cx, int cy)
@@ -117,8 +132,26 @@
 
 	pItem = GetDlgItem(IDC_LABEL_GET_PUT);
 	pItem->GetClientRect(&rcItem);
-	pItem->MoveWindow(12,
+	pItem->MoveWindow(12, 
 		12, rcItem.Width(), rcItem.Height());
+
+	// 璁剧疆鈥滃仠姝换鍔♀�濇寜閽綅缃紙鍙充笅瑙掞級
+	if (m_btnAbortTask.m_hWnd != nullptr) {
+		const int nBtnWidth = 100;
+		const int nBtnHeight = 28;
+		const int nMargin = 12;
+
+		const int nPosX = rcClient.right - nBtnWidth - nMargin;
+		const int nPosY = rcClient.bottom - nBtnHeight - nMargin;
+
+		m_btnAbortTask.MoveWindow(nPosX, nPosY, nBtnWidth, nBtnHeight);
+	}
 }
 
-
+void CRobotTaskDlg::OnBnClickedAbortTask()
+{
+	if (m_pRobotTask) {
+		m_pRobotTask->abort();
+		AfxMessageBox(_T("浠诲姟宸插仠姝€��"));
+	}
+}
\ No newline at end of file

--
Gitblit v1.9.3