From 9d48f280e9a512d894ecdd05d80d8ec3915a704c Mon Sep 17 00:00:00 2001
From: Darker <mr.darker@163.com>
Date: 星期三, 05 三月 2025 17:13:17 +0800
Subject: [PATCH] 1. 完善报警窗口显示 1.1 日志和报警窗口同一时间只能显示一个 1.2 报警窗口跟随主窗口移动 1.3 重写报警窗口的关闭方法
---
SourceCode/Bond/Servo/AlarmDlg.h | 5 ++
SourceCode/Bond/Servo/AlarmDlg.cpp | 51 ++++++++++++++++---------
SourceCode/Bond/Servo/ServoDlg.cpp | 60 ++++++++++++++++++++++++++++-
SourceCode/Bond/Servo/ServoDlg.h | 3 +
4 files changed, 97 insertions(+), 22 deletions(-)
diff --git a/SourceCode/Bond/Servo/AlarmDlg.cpp b/SourceCode/Bond/Servo/AlarmDlg.cpp
index 24721b8..6fc3e88 100644
--- a/SourceCode/Bond/Servo/AlarmDlg.cpp
+++ b/SourceCode/Bond/Servo/AlarmDlg.cpp
@@ -149,6 +149,10 @@
void CAlarmDlg::FillDataToListCtrl(CListCtrl* pListCtrl, const std::vector<AlarmData>& vecData)
{
+ if (pListCtrl == nullptr || pListCtrl->m_hWnd == nullptr) {
+ return;
+ }
+
// 娓呯┖褰撳墠CListCtrl涓殑鎵�鏈夐」
pListCtrl->DeleteAllItems();
@@ -163,14 +167,22 @@
pListCtrl->SetItemText(nItem, 2, str); // 绛夌骇
pListCtrl->SetItemText(nItem, 3, alarm.strDeviceName.c_str()); // 璁惧鍚嶇О
pListCtrl->SetItemText(nItem, 4, alarm.strUnitName.c_str()); // 鍗曞厓鍚嶇О
- pListCtrl->SetItemText(nItem, 5, alarm.strDescription.c_str()); // 鎻忚堪
- pListCtrl->SetItemText(nItem, 6, alarm.strStartTime.c_str()); // 寮�濮嬫椂闂�
- pListCtrl->SetItemText(nItem, 7, alarm.strEndTime.c_str()); // 缁撴潫鏃堕棿
+ pListCtrl->SetItemText(nItem, 5, alarm.strStartTime.c_str()); // 寮�濮嬫椂闂�
+ pListCtrl->SetItemText(nItem, 6, alarm.strEndTime.c_str()); // 缁撴潫鏃堕棿
+ pListCtrl->SetItemText(nItem, 7, alarm.strDescription.c_str()); // 鎻忚堪
}
+
+ // 鑾峰彇鍒楁暟
+ int nColCount = pListCtrl->GetHeaderCtrl()->GetItemCount();
+ pListCtrl->SetColumnWidth(nColCount - 1, LVSCW_AUTOSIZE_USEHEADER);
}
void CAlarmDlg::InsertAlarmData(CListCtrl* pListCtrl, const AlarmData& alarmData)
{
+ if (pListCtrl == nullptr || pListCtrl->m_hWnd == nullptr) {
+ return;
+ }
+
int nRowCount = pListCtrl->GetItemCount();
if (nRowCount >= PAGE_SIZE) {
pListCtrl->DeleteItem(nRowCount - 1);
@@ -186,9 +198,9 @@
pListCtrl->SetItemText(nNewItem, 2, str); // 绛夌骇
pListCtrl->SetItemText(nNewItem, 3, alarmData.strDeviceName.c_str()); // 璁惧鍚嶇О
pListCtrl->SetItemText(nNewItem, 4, alarmData.strUnitName.c_str()); // 鍗曞厓鍚嶇О
- pListCtrl->SetItemText(nNewItem, 5, alarmData.strDescription.c_str()); // 鎻忚堪
- pListCtrl->SetItemText(nNewItem, 6, alarmData.strStartTime.c_str()); // 寮�濮嬫椂闂�
- pListCtrl->SetItemText(nNewItem, 7, alarmData.strEndTime.c_str()); // 缁撴潫鏃堕棿
+ pListCtrl->SetItemText(nNewItem, 5, alarmData.strStartTime.c_str()); // 寮�濮嬫椂闂�
+ pListCtrl->SetItemText(nNewItem, 6, alarmData.strEndTime.c_str()); // 缁撴潫鏃堕棿
+ pListCtrl->SetItemText(nNewItem, 7, alarmData.strDescription.c_str()); // 鎻忚堪
}
std::string CAlarmDlg::getCurrentTimeString()
@@ -215,6 +227,7 @@
BEGIN_MESSAGE_MAP(CAlarmDlg, CDialogEx)
ON_WM_CTLCOLOR()
ON_WM_DESTROY()
+ ON_WM_CLOSE()
ON_WM_SIZE()
ON_CBN_SELCHANGE(IDC_COMBO_DATETIME, &CAlarmDlg::OnCbnSelchangeComboDatetime)
ON_BN_CLICKED(IDC_BUTTON_SEARCH, &CAlarmDlg::OnBnClickedButtonSearch)
@@ -255,12 +268,13 @@
ListView_SetImageList(pListCtrl->GetSafeHwnd(), imageList, LVSIL_SMALL);
pListCtrl->InsertColumn(0, _T(""), LVCFMT_RIGHT, 0);
pListCtrl->InsertColumn(1, _T("璀﹀憡ID"), LVCFMT_LEFT, 50);
- pListCtrl->InsertColumn(2, _T("鎶ヨ绛夌骇"), LVCFMT_LEFT, 50);
- pListCtrl->InsertColumn(3, _T("璁惧鍚嶇О"), LVCFMT_LEFT, 120);
- pListCtrl->InsertColumn(4, _T("鍗曞厓鍚嶇О"), LVCFMT_LEFT, 120);
- pListCtrl->InsertColumn(5, _T("鎻忚堪"), LVCFMT_LEFT, 180);
- pListCtrl->InsertColumn(6, _T("鍙戠敓鏃堕棿"), LVCFMT_LEFT, 180);
- pListCtrl->InsertColumn(7, _T("瑙i櫎鏃堕棿"), LVCFMT_LEFT, 180);
+ pListCtrl->InsertColumn(2, _T("鎶ヨ绛夌骇"), LVCFMT_LEFT, 60);
+ pListCtrl->InsertColumn(3, _T("璁惧鍚嶇О"), LVCFMT_LEFT, 100);
+ pListCtrl->InsertColumn(4, _T("鍗曞厓鍚嶇О"), LVCFMT_LEFT, 100);
+ pListCtrl->InsertColumn(5, _T("鍙戠敓鏃堕棿"), LVCFMT_LEFT, 120);
+ pListCtrl->InsertColumn(6, _T("瑙i櫎鏃堕棿"), LVCFMT_LEFT, 120);
+ pListCtrl->InsertColumn(7, _T("鎻忚堪"), LVCFMT_LEFT, 180);
+ pListCtrl->SetColumnWidth(7, LVSCW_AUTOSIZE_USEHEADER);
// 璁$畻鎬婚〉鏁�
int totalRecords = AlarmManager::getInstance().getTotalAlarmCount("", "", m_strDeviceName, m_strUnitName, m_strKeyword, m_szTimeStart, m_szTimeEnd);
@@ -272,11 +286,6 @@
return TRUE; // return TRUE unless you set the focus to a control
// 寮傚父: OCX 灞炴�ч〉搴旇繑鍥� FALSE
-}
-
-BOOL CAlarmDlg::DestroyWindow()
-{
- return CDialogEx::DestroyWindow();
}
HBRUSH CAlarmDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
@@ -306,6 +315,12 @@
m_pObserver->unsubscribe();
m_pObserver = NULL;
}
+}
+
+void CAlarmDlg::OnClose()
+{
+ ShowWindow(SW_HIDE);
+ GetParent()->PostMessage(ID_MSG_ALARMDLG_HIDE, 0, 0);
}
void CAlarmDlg::OnSize(UINT nType, int cx, int cy)
@@ -456,4 +471,4 @@
// 鐐瑰嚮涓嬩竴椤�
m_nCurPage++;
UpdatePageData(); // 璋冪敤鍒嗛〉鏇存柊鍑芥暟
-}
+}
\ No newline at end of file
diff --git a/SourceCode/Bond/Servo/AlarmDlg.h b/SourceCode/Bond/Servo/AlarmDlg.h
index 4fbfc43..3fbf26d 100644
--- a/SourceCode/Bond/Servo/AlarmDlg.h
+++ b/SourceCode/Bond/Servo/AlarmDlg.h
@@ -2,6 +2,9 @@
#include "afxdialogex.h"
#include "AlarmManager.h"
+
+#define ID_MSG_ALARMDLG_HIDE WM_USER + 1024
+
// CAlarmDlg 瀵硅瘽妗�
class CAlarmDlg : public CDialogEx
@@ -54,9 +57,9 @@
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 鏀寔
virtual BOOL OnInitDialog();
- virtual BOOL DestroyWindow();
afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
afx_msg void OnDestroy();
+ afx_msg void OnClose();
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg void OnCbnSelchangeComboDatetime();
afx_msg void OnBnClickedButtonSearch();
diff --git a/SourceCode/Bond/Servo/ServoDlg.cpp b/SourceCode/Bond/Servo/ServoDlg.cpp
index f6b355c..bb7deba 100644
--- a/SourceCode/Bond/Servo/ServoDlg.cpp
+++ b/SourceCode/Bond/Servo/ServoDlg.cpp
@@ -9,7 +9,6 @@
#include "Common.h"
#include "Log.h"
#include "SecsTestDlg.h"
-#include "AlarmDlg.h"
#include <chrono>
#include <thread>
#include <cmath>
@@ -88,6 +87,7 @@
m_bShowAlarmWnd = FALSE;
m_bIsRobotMoving = FALSE;
m_pLogDlg = nullptr;
+ m_pAlarmDlg = nullptr;
m_pTerminalDisplayDlg = nullptr;
m_pObserver = nullptr;
}
@@ -111,6 +111,7 @@
ON_WM_SIZE()
ON_WM_CLOSE()
ON_MESSAGE(ID_MSG_LOGDLG_HIDE, &CServoDlg::OnLogDlgHide)
+ ON_MESSAGE(ID_MSG_ALARMDLG_HIDE, &CServoDlg::OnAlarmDlgHide)
ON_WM_MOVING()
ON_WM_MOVE()
ON_COMMAND(ID_MENU_FILE_EXIT, &CServoDlg::OnMenuFileExit)
@@ -527,6 +528,13 @@
delete m_pLogDlg;
m_pLogDlg = nullptr;
}
+
+ if (m_pAlarmDlg != nullptr) {
+ m_pAlarmDlg->DestroyWindow();
+ delete m_pAlarmDlg;
+ m_pAlarmDlg = nullptr;
+ }
+
if (m_pTerminalDisplayDlg != nullptr) {
m_pTerminalDisplayDlg->DestroyWindow();
delete m_pTerminalDisplayDlg;
@@ -547,6 +555,16 @@
void CServoDlg::OnBnClickedButtonLog()
{
m_bShowLogWnd = !m_bShowLogWnd;
+
+ // 如果要显示日志窗口,则隐藏报警窗口
+ if (m_bShowLogWnd) {
+ m_bShowAlarmWnd = false;
+ if (m_pAlarmDlg != nullptr) {
+ m_pAlarmDlg->ShowWindow(SW_HIDE);
+ UpdateAlarmBtn();
+ }
+ }
+
if (m_pLogDlg == nullptr) {
m_pLogDlg = new CLogDlg();
m_pLogDlg->Create(IDD_DIALOG_LOG, this);
@@ -772,6 +790,15 @@
return 0;
}
+LRESULT CServoDlg::OnAlarmDlgHide(WPARAM wParam, LPARAM lParam)
+{
+ m_bShowAlarmWnd = FALSE;
+ UpdateAlarmBtn();
+ LOGE("OnAlarmDlgHide");
+
+ return 0;
+}
+
void CServoDlg::OnMoving(UINT fwSide, LPRECT pRect)
{
CDialogEx::OnMoving(fwSide, pRect);
@@ -783,6 +810,12 @@
CRect rcWnd;
GetWindowRect(&rcWnd);
m_pLogDlg->MoveWindow(rcWnd.left, rcWnd.bottom - 8, rcWnd.Width(), 200);
+ }
+
+ if (m_pAlarmDlg != nullptr && !m_pAlarmDlg->IsZoomed()) {
+ CRect rcWnd;
+ GetWindowRect(&rcWnd);
+ m_pAlarmDlg->MoveWindow(rcWnd.left, rcWnd.bottom - 8, rcWnd.Width(), 200);
}
CDialogEx::OnMove(x, y);
@@ -825,6 +858,27 @@
void CServoDlg::OnBnClickedButtonAlarm()
{
// TODO: 在此添加控件通知处理程序代码
- CAlarmDlg dlg;
- dlg.DoModal();
+ m_bShowAlarmWnd = !m_bShowAlarmWnd;
+
+ // 如果要显示报警窗口,则隐藏日志窗口
+ if (m_bShowAlarmWnd) {
+ m_bShowLogWnd = false;
+ if (m_pLogDlg != nullptr) {
+ m_pLogDlg->ShowWindow(SW_HIDE);
+ UpdateLogBtn();
+ }
+ }
+
+ if (m_pAlarmDlg == nullptr) {
+ m_pAlarmDlg = new CAlarmDlg();
+ m_pAlarmDlg->Create(IDD_DIALOG_ALARM, this);
+
+ CRect rcWnd;
+ GetWindowRect(&rcWnd);
+ m_pAlarmDlg->MoveWindow(rcWnd.left, rcWnd.bottom - 8, rcWnd.Width(), 200);
+ }
+ ASSERT(m_pAlarmDlg);
+ m_pAlarmDlg->ShowWindow(m_bShowAlarmWnd ? SW_SHOW : SW_HIDE);
+
+ UpdateAlarmBtn();
}
diff --git a/SourceCode/Bond/Servo/ServoDlg.h b/SourceCode/Bond/Servo/ServoDlg.h
index ab71ed2..dc5314e 100644
--- a/SourceCode/Bond/Servo/ServoDlg.h
+++ b/SourceCode/Bond/Servo/ServoDlg.h
@@ -6,6 +6,7 @@
#include "ServoGraph.h"
#include "BlButton.h"
#include "LogDlg.h"
+#include "AlarmDlg.h"
#include "TerminalDisplayDlg.h"
enum DeviceStatus {
@@ -39,6 +40,7 @@
BOOL m_bShowLogWnd;
BOOL m_bShowAlarmWnd;
CLogDlg* m_pLogDlg;
+ CAlarmDlg* m_pAlarmDlg;
CTerminalDisplayDlg* m_pTerminalDisplayDlg;
@@ -79,6 +81,7 @@
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg void OnClose();
afx_msg LRESULT OnLogDlgHide(WPARAM wParam, LPARAM lParam);
+ afx_msg LRESULT OnAlarmDlgHide(WPARAM wParam, LPARAM lParam);
afx_msg void OnMoving(UINT fwSide, LPRECT pRect);
afx_msg void OnMove(int x, int y);
afx_msg void OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu);
--
Gitblit v1.9.3