LAPTOP-SNT8I5JK\Boounion
2025-06-17 3c387cc7bcd469938fbfac8bc5435bb1e846c70f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// CDevicePropertyDlg.cpp: 实现文件
//
 
#include "stdafx.h"
#include "Servo.h"
#include "afxdialogex.h"
#include "DevicePropertyDlg.h"
 
// CDevicePropertyDlg 对话框
 
IMPLEMENT_DYNAMIC(CDevicePropertyDlg, CDialogEx)
 
CDevicePropertyDlg::CDevicePropertyDlg(CWnd* pParent /*=nullptr*/, int nDeviceID /*=0*/)
    : CDialogEx(IDD_DIALOG_DEVICE_PROPERTY, pParent), m_nDeviceID(nDeviceID)
{
 
}
 
CDevicePropertyDlg::~CDevicePropertyDlg()
{
}
 
void CDevicePropertyDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialogEx::DoDataExchange(pDX);
    DDX_Control(pDX, IDC_LIST_DEVICE_PROPERTY, m_listDeviceProperties);
}
 
 
BEGIN_MESSAGE_MAP(CDevicePropertyDlg, CDialogEx)
END_MESSAGE_MAP()
 
 
// CDevicePropertyDlg 消息处理程序
 
 
BOOL CDevicePropertyDlg::OnInitDialog()
{
    CDialogEx::OnInitDialog();
 
    // TODO:  在此添加额外的初始化
    SERVO::CEquipment* pEquipment = theApp.m_model.m_master.getEquipment(m_nDeviceID);
    if (nullptr == pEquipment) {
        LOGI("<设备ID:%d>获取设备属性失败。", m_nDeviceID);
        return FALSE;
    }
 
    // 修改对话框标题
    std::string strDeviceName = pEquipment->getName();
    SetWindowText(CString(strDeviceName.c_str()));
 
    // 获取所有设备属性
    std::vector<std::pair<std::string, std::string>> properties;
    pEquipment->getProperties(properties);
 
    // 获取ListCtrl的客户区域
    CRect rect;
    m_listDeviceProperties.GetClientRect(&rect);  
    int nTotalWidth = rect.Width();
 
    int nColumnWidth = 150;
    m_listDeviceProperties.InsertColumn(0, _T("名称"), LVCFMT_LEFT, nColumnWidth);
    m_listDeviceProperties.InsertColumn(1, _T("值"), LVCFMT_LEFT, nColumnWidth);
 
    // 遍历容器中的所有属性并输出
    int nItem = 0;
    for (const auto& property : properties) {
        // 插入设备属性
        m_listDeviceProperties.InsertItem(nItem, property.first.c_str());
        m_listDeviceProperties.SetItemText(nItem, 1, property.second.c_str());
        ++nItem;
    }
 
    // 设置第二列宽度
    m_listDeviceProperties.SetColumnWidth(1, nTotalWidth - nColumnWidth);
 
    return TRUE;  // return TRUE unless you set the focus to a control
    // 异常: OCX 属性页应返回 FALSE
}