mrDarker
2025-06-05 8b30a702f2e70073e57ed354519b5df5ea78749c
1. 添加任务停止按钮
已修改4个文件
42 ■■■■■ 文件已修改
SourceCode/Bond/Servo/CRobotCmdTestDlg.cpp 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/CRobotTaskDlg.cpp 37 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/CRobotTaskDlg.h 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/resource.h 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/CRobotCmdTestDlg.cpp
@@ -342,7 +342,7 @@
            }
            return 0;
            });
        });
        CString log;
        if (ret == 0) {
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("任务已停止。"));
    }
}
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();
};
SourceCode/Bond/Servo/resource.h
Binary files differ