From 2cd3e98d5d0bdf341d772b7e75869cd6f2b39280 Mon Sep 17 00:00:00 2001
From: LAPTOP-T815PCOQ\25526 <mr.liuyang@126.com>
Date: 星期三, 27 十一月 2024 09:40:09 +0800
Subject: [PATCH] 1. 监听按钮按下抬起事件
---
SourceCode/Bond/BondEq/View/AxisSettingsDlg.h | 7 --
SourceCode/Bond/BondEq/View/AxisSettingsDlg.cpp | 157 +++++++++++++++++++--------------------------------
2 files changed, 60 insertions(+), 104 deletions(-)
diff --git a/SourceCode/Bond/BondEq/View/AxisSettingsDlg.cpp b/SourceCode/Bond/BondEq/View/AxisSettingsDlg.cpp
index 22d4819..96a53f7 100644
--- a/SourceCode/Bond/BondEq/View/AxisSettingsDlg.cpp
+++ b/SourceCode/Bond/BondEq/View/AxisSettingsDlg.cpp
@@ -260,7 +260,7 @@
void CAxisSettingsDlg::refreshAxisDetails(int nAxisId)
{
- // 鑾峰彇褰撳墠閫変腑鐨勮酱ID
+ // 鑾峰彇杞存暟鎹�
RecipeManager& recipeManager = RecipeManager::getInstance();
auto axisDetails = recipeManager.getAxis(nAxisId);
@@ -588,18 +588,12 @@
ON_BN_CLICKED(IDC_BUTTON_AXIS_ANCHOR_POINT5, &CAxisSettingsDlg::OnBnClickedButtonAxisAnchorPoint5)
ON_BN_CLICKED(IDC_BUTTON_AXIS_TEST_OPR, &CAxisSettingsDlg::OnBnClickedButtonAxisTestOpr)
ON_BN_CLICKED(IDC_BUTTON_AXIS_TEST_STOP, &CAxisSettingsDlg::OnBnClickedButtonAxisTestStop)
- ON_BN_SETFOCUS(IDC_BUTTON_AXIS_TEST_JOG_ADD, &CAxisSettingsDlg::OnBnClickedJogAddDown)
- ON_BN_KILLFOCUS(IDC_BUTTON_AXIS_TEST_JOG_ADD, &CAxisSettingsDlg::OnBnClickedJogAddUp)
- ON_BN_SETFOCUS(IDC_BUTTON_AXIS_TEST_JOG_SUB, &CAxisSettingsDlg::OnBnClickedJogSubDown)
- ON_BN_KILLFOCUS(IDC_BUTTON_AXIS_TEST_JOG_SUB, &CAxisSettingsDlg::OnBnClickedJogSubUp)
ON_CBN_SELCHANGE(IDC_COMBO_AXIS_NAME, &CAxisSettingsDlg::OnSelchangeComboAxisName)
ON_BN_CLICKED(IDC_BUTTON_AXIS_SAVE, &CAxisSettingsDlg::OnBnClickedButtonAxisSave)
ON_WM_SIZE()
ON_WM_CTLCOLOR()
ON_WM_SIZING()
ON_WM_TIMER()
- //ON_WM_LBUTTONDOWN()
- //ON_WM_LBUTTONUP()
END_MESSAGE_MAP()
@@ -678,6 +672,56 @@
return TRUE; // return TRUE unless you set the focus to a control
// 寮傚父: OCX 灞炴�ч〉搴旇繑鍥� FALSE
+}
+
+BOOL CAxisSettingsDlg::PreTranslateMessage(MSG* pMsg)
+{
+ // TODO: 鍦ㄦ娣诲姞涓撶敤浠g爜鍜�/鎴栬皟鐢ㄥ熀绫�
+
+ if (pMsg->message == WM_LBUTTONDOWN)
+ {
+ if (pMsg->hwnd == GetDlgItem(IDC_BUTTON_AXIS_TEST_JOG_ADD)->m_hWnd)
+ {
+ TRACE("JOG+ 鎸夐挳鎸変笅\n");
+ m_bJogAddPressed = TRUE;
+
+ // 鍚姩瀹氭椂鍣ㄨ繛缁彂閫佷俊鍙�
+ SetTimer(TIMER_JOG_ADD, 200, nullptr);
+ handleAxisOperation(AxisOperationType::JOG_ADD, true);
+ }
+ else if (pMsg->hwnd == GetDlgItem(IDC_BUTTON_AXIS_TEST_JOG_SUB)->m_hWnd)
+ {
+ TRACE("JOG- 鎸夐挳鎸変笅\n");
+ m_bJogSubPressed = TRUE;
+
+ // 鍚姩瀹氭椂鍣ㄨ繛缁彂閫佷俊鍙�
+ SetTimer(TIMER_JOG_SUB, 200, nullptr);
+ handleAxisOperation(AxisOperationType::JOG_SUB, true);
+ }
+ }
+ else if (pMsg->message == WM_LBUTTONUP)
+ {
+ if (pMsg->hwnd == GetDlgItem(IDC_BUTTON_AXIS_TEST_JOG_ADD)->m_hWnd)
+ {
+ TRACE("JOG+ 鎸夐挳鏉惧紑\n");
+ m_bJogAddPressed = FALSE;
+
+ // 鍋滄瀹氭椂鍣�
+ KillTimer(TIMER_JOG_ADD);
+ handleAxisOperation(AxisOperationType::JOG_ADD, false);
+ }
+ else if (pMsg->hwnd == GetDlgItem(IDC_BUTTON_AXIS_TEST_JOG_SUB)->m_hWnd)
+ {
+ TRACE("JOG- 鎸夐挳鏉惧紑\n");
+ m_bJogSubPressed = FALSE;
+
+ // 鍋滄瀹氭椂鍣�
+ KillTimer(TIMER_JOG_SUB);
+ handleAxisOperation(AxisOperationType::JOG_SUB, false);
+ }
+ }
+
+ return CDialogEx::PreTranslateMessage(pMsg);
}
void CAxisSettingsDlg::OnSize(UINT nType, int cx, int cy)
@@ -832,46 +876,6 @@
handleAxisOperation(AxisOperationType::STOP, true);
}
-void CAxisSettingsDlg::OnBnClickedJogAddDown()
-{
- TRACE("JOG+ 鎸夐挳鎸変笅\n");
- m_bJogAddPressed = TRUE;
-
- // 鍚姩瀹氭椂鍣ㄨ繛缁彂閫佷俊鍙�
- SetTimer(TIMER_JOG_ADD, 100, nullptr); // 姣� 100ms 鎵ц涓�娆�
- handleAxisOperation(AxisOperationType::JOG_ADD, true);
-}
-
-void CAxisSettingsDlg::OnBnClickedJogAddUp()
-{
- TRACE("JOG+ 鎸夐挳鏉惧紑\n");
- m_bJogAddPressed = FALSE;
-
- // 鍋滄瀹氭椂鍣�
- KillTimer(TIMER_JOG_ADD);
- handleAxisOperation(AxisOperationType::JOG_ADD, false);
-}
-
-void CAxisSettingsDlg::OnBnClickedJogSubDown()
-{
- TRACE("JOG- 鎸夐挳鎸変笅\n");
- m_bJogSubPressed = TRUE;
-
- // 鍚姩瀹氭椂鍣ㄨ繛缁彂閫佷俊鍙�
- SetTimer(TIMER_JOG_SUB, 100, nullptr); // 姣� 100ms 鎵ц涓�娆�
- handleAxisOperation(AxisOperationType::JOG_SUB, true);
-}
-
-void CAxisSettingsDlg::OnBnClickedJogSubUp()
-{
- TRACE("JOG- 鎸夐挳鏉惧紑\n");
- m_bJogSubPressed = FALSE;
-
- // 鍋滄瀹氭椂鍣�
- KillTimer(TIMER_JOG_SUB);
- handleAxisOperation(AxisOperationType::JOG_SUB, false);
-}
-
void CAxisSettingsDlg::OnSelchangeComboAxisName()
{
// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
@@ -905,11 +909,15 @@
updateDataFromUI(axisId);
if (RecipeManager::getInstance().saveRecipe(std::string(CT2A(m_strRecipeName)))) {
writeAxisDataToPLC(axisId);
- AfxMessageBox(_T("淇濆瓨鎴愬姛锛�"));
+ cstrMessage.Format(_T("淇濆瓨杞� [%d] 鍙傛暟鎴愬姛锛�"), axisId);
+ SystemLogManager::getInstance().log(SystemLogManager::LogType::Operation, std::string(CT2A(cstrMessage)));
}
else {
- AfxMessageBox(_T("淇濆瓨澶辫触锛�"));
+ cstrMessage.Format(_T("淇濆瓨杞� [%d] 鍙傛暟澶辫触锛�"), axisId);
+ SystemLogManager::getInstance().log(SystemLogManager::LogType::Error, std::string(CT2A(cstrMessage)));
}
+
+ AfxMessageBox(cstrMessage);
}
void CAxisSettingsDlg::OnTimer(UINT_PTR nIDEvent)
@@ -942,60 +950,13 @@
m_pPLC->readData(MC::SOFT_COMPONENT::D, addr1, readSize, funOnReadData);
}
else if (nIDEvent == TIMER_JOG_ADD && m_bJogAddPressed) {
+ TRACE("鎸佺画鍙戦�� JOG+\n");
handleAxisOperation(AxisOperationType::JOG_ADD, true); // 鎸佺画鍙戦�� JOG+
}
else if (nIDEvent == TIMER_JOG_SUB && m_bJogSubPressed) {
+ TRACE("鎸佺画鍙戦�� JOG-\n");
handleAxisOperation(AxisOperationType::JOG_SUB, true); // 鎸佺画鍙戦�� JOG-
}
CDialogEx::OnTimer(nIDEvent);
}
-
-//void CAxisSettingsDlg::OnLButtonDown(UINT nFlags, CPoint point)
-//{
-// // TODO: 鍦ㄦ娣诲姞娑堟伅澶勭悊绋嬪簭浠g爜鍜�/鎴栬皟鐢ㄩ粯璁ゅ��
-// TRACE("CAxisSettingsDlg::OnLButtonDown\n");
-//
-// // 妫�鏌ラ紶鏍囨槸鍚︾偣鍑诲湪 JOG+ 鎸夐挳涓�
-// CRect rectJogAdd, rectJogSub;
-// GetDlgItem(IDC_BUTTON_AXIS_TEST_JOG_ADD)->GetWindowRect(&rectJogAdd);
-// ScreenToClient(&rectJogAdd);
-//
-// GetDlgItem(IDC_BUTTON_AXIS_TEST_JOG_SUB)->GetWindowRect(&rectJogSub);
-// ScreenToClient(&rectJogSub);
-//
-// if (rectJogAdd.PtInRect(point)) {
-// m_bJogAddPressed = TRUE;
-// handleAxisOperation(AxisOperationType::JOG_ADD, true);
-// SetTimer(TIMER_JOG_ADD, 100, nullptr); // 寮�鍚畾鏃跺櫒
-// }
-// else if (rectJogSub.PtInRect(point)) {
-// m_bJogSubPressed = TRUE;
-// handleAxisOperation(AxisOperationType::JOG_SUB, true);
-// SetTimer(TIMER_JOG_SUB, 100, nullptr); // 寮�鍚畾鏃跺櫒
-// }
-//
-// CDialogEx::OnLButtonDown(nFlags, point); // 璋冪敤鍩虹被鏂规硶
-//}
-//
-//void CAxisSettingsDlg::OnLButtonUp(UINT nFlags, CPoint point)
-//{
-// // TODO: 鍦ㄦ娣诲姞娑堟伅澶勭悊绋嬪簭浠g爜鍜�/鎴栬皟鐢ㄩ粯璁ゅ��
-// TRACE("CAxisSettingsDlg::OnLButtonUp\n");
-//
-// // 鍋滄 JOG+ 鎸夐挳鐨勬搷浣�
-// if (m_bJogAddPressed) {
-// m_bJogAddPressed = FALSE;
-// handleAxisOperation(AxisOperationType::JOG_ADD, false);
-// KillTimer(TIMER_JOG_ADD); // 鍋滄瀹氭椂鍣�
-// }
-//
-// // 鍋滄 JOG- 鎸夐挳鐨勬搷浣�
-// if (m_bJogSubPressed) {
-// m_bJogSubPressed = FALSE;
-// handleAxisOperation(AxisOperationType::JOG_SUB, false);
-// KillTimer(TIMER_JOG_SUB); // 鍋滄瀹氭椂鍣�
-// }
-//
-// CDialogEx::OnLButtonUp(nFlags, point); // 璋冪敤鍩虹被鏂规硶
-//}
diff --git a/SourceCode/Bond/BondEq/View/AxisSettingsDlg.h b/SourceCode/Bond/BondEq/View/AxisSettingsDlg.h
index 971ee59..bd1f4d6 100644
--- a/SourceCode/Bond/BondEq/View/AxisSettingsDlg.h
+++ b/SourceCode/Bond/BondEq/View/AxisSettingsDlg.h
@@ -83,6 +83,7 @@
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 鏀寔
virtual BOOL OnInitDialog();
+ virtual BOOL PreTranslateMessage(MSG* pMsg);
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg void OnSizing(UINT fwSide, LPRECT pRect);
afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
@@ -100,14 +101,8 @@
afx_msg void OnBnClickedButtonAxisAnchorPoint5();
afx_msg void OnBnClickedButtonAxisTestOpr();
afx_msg void OnBnClickedButtonAxisTestStop();
- afx_msg void OnBnClickedJogAddDown();
- afx_msg void OnBnClickedJogAddUp();
- afx_msg void OnBnClickedJogSubDown();
- afx_msg void OnBnClickedJogSubUp();
afx_msg void OnSelchangeComboAxisName();
afx_msg void OnBnClickedButtonAxisSave();
afx_msg void OnTimer(UINT_PTR nIDEvent);
- //afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
- //afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
DECLARE_MESSAGE_MAP()
};
--
Gitblit v1.9.3