mrDarker
2025-04-01 1bc4fecb9cc1641ed3ad0a2fda30766fc06fb13e
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
// CPanelEquipment.cpp: 实现文件
//
 
#include "stdafx.h"
#include "Servo.h"
#include "CPanelEquipment.h"
#include "afxdialogex.h"
#include "Common.h"
#include "VerticalLine.h"
 
 
// CPanelEquipment 对话框
 
IMPLEMENT_DYNAMIC(CPanelEquipment, CDialogEx)
 
CPanelEquipment::CPanelEquipment(CWnd* pParent /*=nullptr*/)
    : CDialogEx(IDD_PANEL_EQUIPMENT, pParent)
{
    m_crBkgnd = PANEL_EQUIPMENT_BACKGROUND_COLOR;
    m_hbrBkgnd = nullptr;
    m_nPanelWidth = 188;
    m_pEquipment = nullptr;
}
 
CPanelEquipment::~CPanelEquipment()
{
}
 
void CPanelEquipment::DoDataExchange(CDataExchange* pDX)
{
    CDialogEx::DoDataExchange(pDX);
    DDX_Control(pDX, IDC_MFCPROPERTYGRID1, m_gridCtrl);
}
 
 
BEGIN_MESSAGE_MAP(CPanelEquipment, CDialogEx)
    ON_WM_CTLCOLOR()
    ON_WM_DESTROY()
    ON_WM_SIZE()
    ON_NOTIFY(BYVERTICALLINE_MOVEX, IDC_LINE1, &CPanelEquipment::OnVLineMoveX)
    ON_BN_CLICKED(IDC_BUTTON_CLOSE, &CPanelEquipment::OnBnClickedButtonClose)
END_MESSAGE_MAP()
 
 
// CPanelEquipment 消息处理程序
 
 
int CPanelEquipment::getPanelWidth()
{
    return m_nPanelWidth;
}
 
void CPanelEquipment::SetEquipment(SERVO::CEquipment* pEquipment)
{
    m_pEquipment = pEquipment;
    ASSERT(m_pEquipment);
 
    if (::IsWindow(m_hWnd)) {
        SetDlgItemText(IDC_LABEL_TITLE, m_pEquipment->getName().c_str());
    }
}
 
void CPanelEquipment::loadDataFromEquipment(SERVO::CEquipment* pEquipment)
{
    m_pEquipment = pEquipment;
    ASSERT(m_pEquipment);
 
 
    // 先清空所有
    m_gridCtrl.RemoveAll();
 
 
    // 加载数据
    SetDlgItemText(IDC_LABEL_TITLE, pEquipment->getName().c_str());
    SERVO::CAttributeVector attrubutes;
    pEquipment->getAttributeVector(attrubutes);
    unsigned int nSize = attrubutes.size();
    for (unsigned int i = 0; i < nSize; i++) {
        SERVO::CAttribute* pAttribute = attrubutes.getAttribute(i);
        CMFCPropertyGridProperty* pProperty = new CMFCPropertyGridProperty(
            pAttribute->getName().c_str(),
            pAttribute->getValue().c_str(),
            pAttribute->getDescription().c_str());
        pProperty->AllowEdit(FALSE);
        m_gridCtrl.AddProperty(pProperty);
    }
}
 
BOOL CPanelEquipment::OnInitDialog()
{
    CDialogEx::OnInitDialog();
 
    // 关闭按钮
    CString strIcon1;
    strIcon1.Format(_T("%s\\Res\\panel_close_24_b.ico"), theApp.m_strAppDir);
    HICON hIcon1 = (HICON)::LoadImage(AfxGetInstanceHandle(),
        strIcon1, IMAGE_ICON, 24, 24,
        LR_LOADFROMFILE | LR_DEFAULTCOLOR | LR_CREATEDIBSECTION | LR_DEFAULTSIZE);
    m_btnClose.SubclassDlgItem(IDC_BUTTON_CLOSE, this);
    m_btnClose.SetIcon(hIcon1, hIcon1, 24);
    m_btnClose.SetFaceColor(m_crBkgnd);
    m_btnClose.SetFrameColor(m_crBkgnd);
    m_btnClose.SetFrameColor(BS_HOVER, RGB(218, 218, 218));
    m_btnClose.SetFrameColor(BS_PRESS, RGB(168, 168, 168));
 
    CVerticalLine* pLine1 = CVerticalLine::Hook(GetDlgItem(IDC_LINE1)->GetSafeHwnd());
    pLine1->SetBkgndColor(RGB(225, 225, 225));
    pLine1->SetLineColor(RGB(198, 198, 198));
    pLine1->EnableResize();
 
 
    // 读取面板宽
    CString strIniFile;
    strIniFile.Format(_T("%s\\%s.ini"), (LPTSTR)(LPCTSTR)theApp.m_strAppDir, (LPTSTR)(LPCTSTR)theApp.m_strAppFile);
    m_nPanelWidth = GetPrivateProfileInt(_T("App"), _T("EquipmentPanelWidth"),
        int((double)GetSystemMetrics(SM_CXSCREEN) * 0.25), (LPTSTR)(LPCTSTR)strIniFile);
 
    return TRUE;  // return TRUE unless you set the focus to a control
                  // 异常: OCX 属性页应返回 FALSE
}
 
 
HBRUSH CPanelEquipment::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
    HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor);
 
    if (nCtlColor == CTLCOLOR_STATIC) {
        pDC->SetBkColor(m_crBkgnd);
        pDC->SetTextColor(RGB(0, 0, 0));
    }
 
    if (m_hbrBkgnd == nullptr) {
        m_hbrBkgnd = CreateSolidBrush(m_crBkgnd);
    }
 
    return m_hbrBkgnd;
}
 
 
void CPanelEquipment::OnDestroy()
{
    CDialogEx::OnDestroy();
 
    if (m_hbrBkgnd != nullptr) {
        ::DeleteObject(m_hbrBkgnd);
    }
}
 
 
void CPanelEquipment::OnSize(UINT nType, int cx, int cy)
{
    CDialogEx::OnSize(nType, cx, cy);
    if (GetDlgItem(IDC_LINE1) == nullptr) return;
 
    CWnd* pItem;
    CRect rcClient, rcItem;
 
    GetClientRect(&rcClient);
    pItem = GetDlgItem(IDC_LINE1);
    pItem->MoveWindow(rcClient.right - 3, 0, 3, rcClient.Height());
 
    int x2 = rcClient.right - 6;
    int y = 3;
    pItem = GetDlgItem(IDC_BUTTON_CLOSE);
    pItem->GetWindowRect(&rcItem);
    pItem->MoveWindow(x2 - rcItem.Width(), y, rcItem.Width(), rcItem.Height());
    x2 -= rcItem.Width();
    x2 -= 3;
 
    pItem = GetDlgItem(IDC_LABEL_TITLE);
    pItem->GetWindowRect(&rcItem);
    pItem->MoveWindow(5, y, x2 - 5, rcItem.Height());
    y += rcItem.Height();
    y += 8;
 
    GetDlgItem(IDC_MFCPROPERTYGRID1)->MoveWindow(5, y, rcClient.Width() - 8, rcClient.Height() - 3 - y);
}
 
#define EQUIPMENT_PANEL_MIN_WIDTH        88
#define EQUIPMENT_PANEL_MAX_WIDTH        588
void CPanelEquipment::OnVLineMoveX(NMHDR* nmhdr, LRESULT* result)
{
    BYVERTICALLINE_NMHDR* pNmhdrex = (BYVERTICALLINE_NMHDR*)nmhdr;
    int x = pNmhdrex->dwData;
    m_nPanelWidth += x;
    m_nPanelWidth = max(m_nPanelWidth, EQUIPMENT_PANEL_MIN_WIDTH);
    m_nPanelWidth = min(m_nPanelWidth, EQUIPMENT_PANEL_MAX_WIDTH);
    GetParent()->SendMessage(ID_MSG_PANEL_RESIZE, m_nPanelWidth, 0);
 
    CString strIniFile, strValue;
    strIniFile.Format(_T("%s\\%s.ini"), (LPTSTR)(LPCTSTR)theApp.m_strAppDir, (LPTSTR)(LPCTSTR)theApp.m_strAppFile);
    strValue.Format(_T("%d"), m_nPanelWidth);
    WritePrivateProfileString(_T("App"), _T("EquipmentPanelWidth"),
        (LPTSTR)(LPCTSTR)strValue, (LPTSTR)(LPCTSTR)strIniFile);
    OnSize(0, 0, 0);
 
    *result = 0;
}
 
void CPanelEquipment::OnBnClickedButtonClose()
{
    ShowWindow(SW_HIDE);
    GetParent()->SendMessage(ID_MSG_PANEL_RESIZE, m_nPanelWidth, 0);
}