// 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> 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 }