From 8b30a702f2e70073e57ed354519b5df5ea78749c Mon Sep 17 00:00:00 2001
From: mrDarker <mr.darker@163.com>
Date: 星期四, 05 六月 2025 08:45:39 +0800
Subject: [PATCH] 1. 添加任务停止按钮
---
SourceCode/Bond/Servo/resource.h | 0
SourceCode/Bond/Servo/CRobotCmdTestDlg.cpp | 2 +-
SourceCode/Bond/Servo/CRobotTaskDlg.h | 3 +++
SourceCode/Bond/Servo/CRobotTaskDlg.cpp | 37 +++++++++++++++++++++++++++++++++++--
4 files changed, 39 insertions(+), 3 deletions(-)
diff --git a/SourceCode/Bond/Servo/CRobotCmdTestDlg.cpp b/SourceCode/Bond/Servo/CRobotCmdTestDlg.cpp
index ea62463..804335e 100644
--- a/SourceCode/Bond/Servo/CRobotCmdTestDlg.cpp
+++ b/SourceCode/Bond/Servo/CRobotCmdTestDlg.cpp
@@ -342,7 +342,7 @@
}
return 0;
- });
+ });
CString log;
if (ret == 0) {
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
diff --git a/SourceCode/Bond/Servo/CRobotTaskDlg.h b/SourceCode/Bond/Servo/CRobotTaskDlg.h
index 8754432..946550a 100644
--- a/SourceCode/Bond/Servo/CRobotTaskDlg.h
+++ b/SourceCode/Bond/Servo/CRobotTaskDlg.h
@@ -21,6 +21,8 @@
private:
SERVO::CRobotTask* m_pRobotTask;
+ CButton m_btnAbortTask;
+ CFont m_fontButton;
// 瀵硅瘽妗嗘暟鎹�
@@ -38,4 +40,5 @@
afx_msg void OnDestroy();
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg void OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized);
+ afx_msg void OnBnClickedAbortTask();
};
diff --git a/SourceCode/Bond/Servo/resource.h b/SourceCode/Bond/Servo/resource.h
index 8e4c2de..4a13461 100644
--- a/SourceCode/Bond/Servo/resource.h
+++ b/SourceCode/Bond/Servo/resource.h
Binary files differ
--
Gitblit v1.9.3