LAPTOP-SNT8I5JK\Boounion
2025-03-10 25bce5c9eaeddb5e2a28ed6b0d7c70c4903ab258
1.警告窗口保存列宽;
已添加2个文件
已修改4个文件
176 ■■■■■ 文件已修改
SourceCode/Bond/Servo/AlarmDlg.cpp 48 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/AlarmDlg.h 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/ListCtrlEx.cpp 93 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/ListCtrlEx.h 29 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/Servo.vcxproj 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/Servo.vcxproj.filters 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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("解除时间"), 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("解除时间"), 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);
    }
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
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;
}
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);
};
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" />
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" />