From 25bce5c9eaeddb5e2a28ed6b0d7c70c4903ab258 Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期一, 10 三月 2025 17:00:15 +0800
Subject: [PATCH] 1.警告窗口保存列宽;
---
SourceCode/Bond/Servo/AlarmDlg.h | 2
SourceCode/Bond/Servo/Servo.vcxproj | 2
SourceCode/Bond/Servo/Servo.vcxproj.filters | 2
SourceCode/Bond/Servo/AlarmDlg.cpp | 48 ++++++++++++---
SourceCode/Bond/Servo/ListCtrlEx.h | 29 +++++++++
SourceCode/Bond/Servo/ListCtrlEx.cpp | 93 +++++++++++++++++++++++++++++++
6 files changed, 166 insertions(+), 10 deletions(-)
diff --git a/SourceCode/Bond/Servo/AlarmDlg.cpp b/SourceCode/Bond/Servo/AlarmDlg.cpp
index 3c3ff33..83f7837 100644
--- a/SourceCode/Bond/Servo/AlarmDlg.cpp
+++ b/SourceCode/Bond/Servo/AlarmDlg.cpp
@@ -141,6 +141,7 @@
GetDlgItem(IDC_BUTTON_NEXT_PAGE)->EnableWindow(m_nCurPage < m_nTotalPages);
}
+static char* pszAlarmLevel[] = {"Warning", "Error"};
void CAlarmDlg::FillDataToListCtrl(CListCtrl* pListCtrl, const std::vector<AlarmData>& vecData)
{
if (pListCtrl == nullptr || pListCtrl->m_hWnd == nullptr) {
@@ -157,8 +158,7 @@
// 璁剧疆鍒楀唴瀹�
str.Format(_T("%d"), alarm.nId);
pListCtrl->SetItemText(nItem, 1, str); // 鎶ヨID
- str.Format(_T("%d"), alarm.nSeverityLevel);
- pListCtrl->SetItemText(nItem, 2, str); // 绛夌骇
+ pListCtrl->SetItemText(nItem, 2, pszAlarmLevel[alarm.nSeverityLevel % 2]); // 绛夌骇
pListCtrl->SetItemText(nItem, 3, alarm.strDeviceName.c_str()); // 璁惧鍚嶇О
pListCtrl->SetItemText(nItem, 4, alarm.strUnitName.c_str()); // 鍗曞厓鍚嶇О
pListCtrl->SetItemText(nItem, 5, alarm.strStartTime.c_str()); // 寮�濮嬫椂闂�
@@ -214,6 +214,7 @@
{
DDX_Control(pDX, IDC_DATETIMEPICKER_START, m_dateTimeStart);
DDX_Control(pDX, IDC_DATETIMEPICKER_END, m_dateTimeEnd);
+ DDX_Control(pDX, IDC_LIST_ALARM, m_listCtrl);
CDialogEx::DoDataExchange(pDX);
}
@@ -251,6 +252,17 @@
m_dateTimeStart.EnableWindow(FALSE);
m_dateTimeEnd.EnableWindow(FALSE);
+
+ // 璇诲嚭鍒楀
+ CString strIniFile, strItem;
+ strIniFile.Format(_T("%s\\configuration.ini"), (LPTSTR)(LPCTSTR)theApp.m_strAppDir);
+ int width[8] = { 0, 80, 180, 80, 80, 100, 80, 180};
+ for (int i = 0; i < 8; i++) {
+ strItem.Format(_T("Col_%d_Width"), i);
+ width[i] = GetPrivateProfileInt("AlarmListCtrl", strItem, width[i], strIniFile);
+ }
+
+
// 鎶ヨ〃鎺т欢
CListCtrl* pListCtrl = (CListCtrl*)GetDlgItem(IDC_LIST_ALARM);
DWORD dwStyle = pListCtrl->GetExtendedStyle();
@@ -260,15 +272,17 @@
HIMAGELIST imageList = ImageList_Create(24, 24, ILC_COLOR24, 1, 1);
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, 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->InsertColumn(0, _T(""), LVCFMT_RIGHT, width[0]);
+ pListCtrl->InsertColumn(1, _T("璀﹀憡ID"), LVCFMT_LEFT, width[1]);
+ pListCtrl->InsertColumn(2, _T("鎶ヨ绛夌骇"), LVCFMT_LEFT, width[2]);
+ pListCtrl->InsertColumn(3, _T("璁惧鍚嶇О"), LVCFMT_LEFT, width[3]);
+ pListCtrl->InsertColumn(4, _T("鍗曞厓鍚嶇О"), LVCFMT_LEFT, width[4]);
+ pListCtrl->InsertColumn(5, _T("鍙戠敓鏃堕棿"), LVCFMT_LEFT, width[5]);
+ pListCtrl->InsertColumn(6, _T("瑙i櫎鏃堕棿"), LVCFMT_LEFT, width[6]);
+ pListCtrl->InsertColumn(7, _T("鎻忚堪"), LVCFMT_LEFT, width[7]);
pListCtrl->SetColumnWidth(7, LVSCW_AUTOSIZE_USEHEADER);
+
+
// 璁$畻鎬婚〉鏁�
int totalRecords = AlarmManager::getInstance().getTotalAlarmCount("", "", m_strDeviceName, m_strUnitName, m_strKeyword, m_szTimeStart, m_szTimeEnd);
@@ -301,6 +315,20 @@
{
CDialogEx::OnDestroy();
+
+ // 淇濆瓨鍒楀
+ CString strIniFile, strItem, strTemp;
+ strIniFile.Format(_T("%s\\configuration.ini"), (LPTSTR)(LPCTSTR)theApp.m_strAppDir);
+ CHeaderCtrl* pHeader = m_listCtrl.GetHeaderCtrl();
+ for (int i = 0; i < pHeader->GetItemCount(); i++) {
+ RECT rect;
+ pHeader->GetItemRect(i, &rect);
+ strItem.Format(_T("Col_%d_Width"), i);
+ strTemp.Format(_T("%d"), rect.right - rect.left);
+ WritePrivateProfileString("AlarmListCtrl", strItem, strTemp, strIniFile);
+ }
+
+
if (m_hbrBkgnd != nullptr) {
::DeleteObject(m_hbrBkgnd);
}
diff --git a/SourceCode/Bond/Servo/AlarmDlg.h b/SourceCode/Bond/Servo/AlarmDlg.h
index 3fbf26d..c1ef5dc 100644
--- a/SourceCode/Bond/Servo/AlarmDlg.h
+++ b/SourceCode/Bond/Servo/AlarmDlg.h
@@ -1,6 +1,7 @@
锘�#pragma once
#include "afxdialogex.h"
#include "AlarmManager.h"
+#include "ListCtrlEx.h"
#define ID_MSG_ALARMDLG_HIDE WM_USER + 1024
@@ -48,6 +49,7 @@
// 鎺т欢
CDateTimeCtrl m_dateTimeStart;
CDateTimeCtrl m_dateTimeEnd;
+ CListCtrlEx m_listCtrl;
// 瀵硅瘽妗嗘暟鎹�
#ifdef AFX_DESIGN_TIME
diff --git a/SourceCode/Bond/Servo/ListCtrlEx.cpp b/SourceCode/Bond/Servo/ListCtrlEx.cpp
new file mode 100644
index 0000000..d302c4c
--- /dev/null
+++ b/SourceCode/Bond/Servo/ListCtrlEx.cpp
@@ -0,0 +1,93 @@
+#include "stdafx.h"
+#include "ListCtrlEx.h"
+
+
+CListCtrlEx::CListCtrlEx()
+{
+}
+
+
+CListCtrlEx::~CListCtrlEx()
+{
+}
+BEGIN_MESSAGE_MAP(CListCtrlEx, CListCtrl)
+ ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, &CListCtrlEx::OnNMCustomdraw)
+END_MESSAGE_MAP()
+
+
+void CListCtrlEx::OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult)
+{
+ LPNMCUSTOMDRAW pNMCD = reinterpret_cast<LPNMCUSTOMDRAW>(pNMHDR);
+ // TODO: 在此添加控件通知处理程序代码
+ *pResult = CDRF_DODEFAULT;
+
+ NMLVCUSTOMDRAW * lplvdr = (NMLVCUSTOMDRAW*)pNMHDR;
+ NMCUSTOMDRAW &nmcd = lplvdr->nmcd;
+ switch (lplvdr->nmcd.dwDrawStage)//判断状态
+ {
+ case CDDS_PREPAINT:
+ {
+ *pResult = CDRF_NOTIFYITEMDRAW;
+ break;
+ }
+ case CDDS_ITEMPREPAINT://如果为画ITEM之前就要进行颜色的改变
+ {
+ // 根据在 SetItemColor(DWORD iItem, COLORREF color) 设置的
+ // ITEM号和COLORREF 在摸板中查找,然后进行颜色赋值。
+ //LISTITEMEX_9& itemex = m_listItemColor.GetAt(m_listItemColor.FindIndex(nmcd.dwItemSpec));
+ //lplvdr->clrText = itemex.colText;
+ //lplvdr->clrTextBk = itemex.colTextBk;
+ //*pResult = CDRF_DODEFAULT;
+
+ if (nmcd.dwItemSpec % 2 == 0) {
+ lplvdr->clrText = RGB(0, 0, 0);
+ lplvdr->clrTextBk = RGB(235, 235, 235);
+ *pResult = CDRF_DODEFAULT;
+ }
+ else {
+ lplvdr->clrText = RGB(0, 0, 0);
+ lplvdr->clrTextBk = RGB(255, 255, 255);
+ *pResult = CDRF_DODEFAULT;
+ }
+
+
+ break;
+ }
+ }
+
+}
+
+void CListCtrlEx::SetItemColor(DWORD_PTR iItem, COLORREF TextColor, COLORREF TextBkColor)
+{
+ if (iItem >= m_listItemColor.GetSize()) return;
+ LISTITEMEX_9& itemex = m_listItemColor.GetAt(m_listItemColor.FindIndex(iItem));
+ itemex.colText = TextColor;
+ itemex.colTextBk = TextBkColor;
+ this->RedrawItems(iItem, iItem); // 重新染色
+ UpdateWindow();
+}
+
+
+LRESULT CListCtrlEx::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
+{
+ int nRet = CListCtrl::WindowProc(message, wParam, lParam);
+ if (message == LVM_INSERTITEM) {
+ if (nRet != -1) {
+ LISTITEMEX_9 itemex = {RGB(0,0,0), RGB(255, 255, 255)};
+ LVITEM* p = (LVITEM*)lParam;
+ m_listItemColor.InsertBefore(m_listItemColor.FindIndex(p->iItem), itemex);
+ }
+ }
+ else if (message == LVM_DELETEITEM) {
+ if (nRet != 0) {
+ m_listItemColor.RemoveAt(m_listItemColor.FindIndex(wParam));
+ }
+ }
+ else if (message == LVM_DELETEALLITEMS) {
+ if (nRet != 0) {
+ m_listItemColor.RemoveAll();
+ }
+ }
+
+ return nRet;
+}
diff --git a/SourceCode/Bond/Servo/ListCtrlEx.h b/SourceCode/Bond/Servo/ListCtrlEx.h
new file mode 100644
index 0000000..7d4de1f
--- /dev/null
+++ b/SourceCode/Bond/Servo/ListCtrlEx.h
@@ -0,0 +1,29 @@
+#pragma once
+#include "afxcmn.h"
+
+typedef struct
+{
+ COLORREF colText;
+ COLORREF colTextBk;
+} LISTITEMEX_9;
+
+class CListCtrlEx :
+ public CListCtrl
+{
+public:
+ CListCtrlEx();
+ ~CListCtrlEx();
+
+public:
+ void SetItemColor(DWORD_PTR iItem, COLORREF TextColor, COLORREF TextBkColor);
+
+
+private:
+ CList<LISTITEMEX_9, LISTITEMEX_9&> m_listItemColor;
+
+private:
+ DECLARE_MESSAGE_MAP()
+ afx_msg void OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult);
+ virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
+};
+
diff --git a/SourceCode/Bond/Servo/Servo.vcxproj b/SourceCode/Bond/Servo/Servo.vcxproj
index 15c767a..f603941 100644
--- a/SourceCode/Bond/Servo/Servo.vcxproj
+++ b/SourceCode/Bond/Servo/Servo.vcxproj
@@ -224,6 +224,7 @@
<ClInclude Include="Context.h" />
<ClInclude Include="HsmsAction.h" />
<ClInclude Include="HsmsPassive.h" />
+ <ClInclude Include="ListCtrlEx.h" />
<ClInclude Include="Log.h" />
<ClInclude Include="LogDlg.h" />
<ClInclude Include="LogEdit.h" />
@@ -269,6 +270,7 @@
<ClCompile Include="Context.cpp" />
<ClCompile Include="HsmsAction.cpp" />
<ClCompile Include="HsmsPassive.cpp" />
+ <ClCompile Include="ListCtrlEx.cpp" />
<ClCompile Include="Log.cpp" />
<ClCompile Include="LogDlg.cpp" />
<ClCompile Include="LogEdit.cpp" />
diff --git a/SourceCode/Bond/Servo/Servo.vcxproj.filters b/SourceCode/Bond/Servo/Servo.vcxproj.filters
index c1113c1..477da7b 100644
--- a/SourceCode/Bond/Servo/Servo.vcxproj.filters
+++ b/SourceCode/Bond/Servo/Servo.vcxproj.filters
@@ -52,6 +52,7 @@
<ClCompile Include="CWriteStep.cpp" />
<ClCompile Include="CEqCimModeChangeStep.cpp" />
<ClCompile Include="CPanelEquipment.cpp" />
+ <ClCompile Include="ListCtrlEx.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="AlarmManager.h" />
@@ -102,6 +103,7 @@
<ClInclude Include="CWriteStep.h" />
<ClInclude Include="CEqCimModeChangeStep.h" />
<ClInclude Include="CPanelEquipment.h" />
+ <ClInclude Include="ListCtrlEx.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Servo.rc" />
--
Gitblit v1.9.3