LAPTOP-SNT8I5JK\Boounion
2025-09-22 9e9e63ef44ff672989d7b78bf37afb2054267671
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
// CPanelProject.cpp: 实现文件
//
 
#include "stdafx.h"
#include "BondEq.h"
#include "CPanelProject.h"
#include "afxdialogex.h"
 
 
// CPanelEquipment 对话框
 
IMPLEMENT_DYNAMIC(CPanelProject, CDialogEx)
 
CPanelProject::CPanelProject(CWnd* pParent /*=nullptr*/)
    : CDialogEx(IDD_PANEL_PROJECT, pParent)
{
    m_crBkgnd = RGB(252, 252, 255);
    m_hbrBkgnd = nullptr;
    m_nPanelWidth = int((double)GetSystemMetrics(SM_CXSCREEN) * 0.25);
    m_pAccordionWnd = nullptr;
    //m_pPageRemoteEqs = nullptr;
    m_pPageMain = nullptr;
    m_pPageComponents = nullptr;
}
 
CPanelProject::~CPanelProject()
{
}
 
void CPanelProject::DoDataExchange(CDataExchange* pDX)
{
    CDialogEx::DoDataExchange(pDX);
}
 
 
BEGIN_MESSAGE_MAP(CPanelProject, CDialogEx)
    ON_WM_SIZE()
    ON_WM_CTLCOLOR()
    ON_WM_DESTROY()
    ON_NOTIFY(BYVERTICALLINE_MOVEX, IDC_LINE1, &CPanelProject::OnVLineMoveX)
END_MESSAGE_MAP()
 
 
// CPanelEquipment 消息处理程序
 
 
BOOL CPanelProject::OnInitDialog()
{
    CDialogEx::OnInitDialog();
 
 
    // 读取面板宽
    CString strIniFile;
    strIniFile.Format(_T("%s\\configuration.ini"), (LPTSTR)(LPCTSTR)theApp.m_strAppDir);
    m_nPanelWidth = GetPrivateProfileInt(_T("App"), _T("PanelEquipmentWidth"),
        int((double)GetSystemMetrics(SM_CXSCREEN) * 0.25), (LPTSTR)(LPCTSTR)strIniFile);
 
    CVerticalLine* pLine = CVerticalLine::Hook(GetDlgItem(IDC_LINE1)->GetSafeHwnd());
    pLine->EnableResize();
 
 
    // 分组展开收起控件
    CString strExpandIcon, strCloseIcon;
    strExpandIcon.Format(_T("%s\\res\\arrow_down.ico"), (LPTSTR)(LPCTSTR)theApp.m_strAppDir);
    strCloseIcon.Format(_T("%s\\res\\arrow_right.ico"), (LPTSTR)(LPCTSTR)theApp.m_strAppDir);
 
    m_pAccordionWnd = CAccordionWnd::FromHandle(GetDlgItem(IDC_ACCORDION_WND1)->m_hWnd);
    m_pAccordionWnd->SetFrameColor(RGB(220, 220, 220), TRUE);
    m_pAccordionWnd->Setpadding(PADDING_LEFT, 2);
    m_pAccordionWnd->Setpadding(PADDING_TOP, 2);
    m_pAccordionWnd->Setpadding(PADDING_RIGHT, 2);
    m_pAccordionWnd->Setpadding(PADDING_BOTTOM, 2);
    m_pAccordionWnd->LoadExpandIcon(strExpandIcon, strCloseIcon);
    
    //m_pPageRemoteEqs = new CProjectPageRemoteEqs();
    //m_pPageRemoteEqs->Create(IDD_PROJECT_PAGE_REMOTEEQS, GetDlgItem(IDC_ACCORDION_WND1));
    //m_pPageRemoteEqs->ShowWindow(SW_SHOW);
    //m_pAccordionWnd->AddItem("远程设备", m_pPageRemoteEqs, 0, TRUE, TRUE);
 
    m_pPageMain = new CProjectPageMain();
    m_pPageMain->SetPLC(theApp.m_model.getBonder().getPLC("PLC(1)"));
    m_pPageMain->Create(IDD_PROJECT_PAGE_MAIN, GetDlgItem(IDC_ACCORDION_WND1));
    m_pPageMain->ShowWindow(SW_SHOW);
    m_pAccordionWnd->AddItem("主页面", m_pPageMain, 0, TRUE, TRUE);
    
    m_pPageComponents = new CProjectPageComponents();
    m_pPageComponents->Create(IDD_PROJECT_PAGE_COMPONENTS, GetDlgItem(IDC_ACCORDION_WND1));
    m_pPageComponents->ShowWindow(SW_SHOW);
    m_pAccordionWnd->AddItem("组件列表", m_pPageComponents, -1, TRUE, TRUE);
 
    return TRUE;  // return TRUE unless you set the focus to a control
                  // 异常: OCX 属性页应返回 FALSE
}
 
void CPanelProject::OnSize(UINT nType, int cx, int cy)
{
    CDialogEx::OnSize(nType, cx, cy);
    if(GetDlgItem(IDC_LINE1) == nullptr) return;
    Resize();
}
 
HBRUSH CPanelProject::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
    HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor);
 
    if (nCtlColor == CTLCOLOR_STATIC) {
        pDC->SetBkColor(m_crBkgnd);
    }
 
    if (m_hbrBkgnd == nullptr) {
        m_hbrBkgnd = CreateSolidBrush(m_crBkgnd);
    }
 
    return m_hbrBkgnd;
}
 
void CPanelProject::OnDestroy()
{
    CDialogEx::OnDestroy();
 
    if (m_hbrBkgnd != nullptr) {
        ::DeleteObject(m_hbrBkgnd);
    }
 
    if (m_pPageComponents != nullptr) {
        m_pPageComponents->DestroyWindow();
        delete m_pPageComponents;
        m_pPageComponents = nullptr;
    }
 
    //if (m_pPageRemoteEqs != nullptr) {
    //    m_pPageRemoteEqs->DestroyWindow();
    //    delete m_pPageRemoteEqs;
    //    m_pPageRemoteEqs = nullptr;
    //}
 
    if (m_pPageMain != nullptr) {
        m_pPageMain->DestroyWindow();
        delete m_pPageMain;
        m_pPageMain = nullptr;
    }
}
 
void CPanelProject::Resize()
{
    CRect rcClient, rcItem;
    GetClientRect(&rcClient);
 
    CWnd* pLine = GetDlgItem(IDC_LINE1);
    pLine->MoveWindow(rcClient.right - 2, 0, 2, rcClient.Height());
 
    GetDlgItem(IDC_ACCORDION_WND1)->MoveWindow(0, 0, rcClient.Width() - 2, rcClient.Height());
}
 
#define LEFT_PANEL_MIN_WIDTH        80
#define LEFT_PANEL_MAX_WIDTH        880
void CPanelProject::OnVLineMoveX(NMHDR* nmhdr, LRESULT* result)
{
    BYVERTICALLINE_NMHDR* pNmhdrex = (BYVERTICALLINE_NMHDR*)nmhdr;
    int x = pNmhdrex->dwData;
    m_nPanelWidth += x;
    m_nPanelWidth = max(m_nPanelWidth, LEFT_PANEL_MIN_WIDTH);
    m_nPanelWidth = min(m_nPanelWidth, LEFT_PANEL_MAX_WIDTH);
    GetParent()->SendMessage(WM_SIZE, 0, 0);
 
    CString strIniFile, strValue;
    strIniFile.Format(_T("%s\\configuration.ini"), (LPTSTR)(LPCTSTR)theApp.m_strAppDir);
    strValue.Format(_T("%d"), m_nPanelWidth);
    WritePrivateProfileString(_T("App"), _T("PanelEquipmentWidth"),
        (LPTSTR)(LPCTSTR)strValue, (LPTSTR)(LPCTSTR)strIniFile);
 
    *result = 0;
}
 
int CPanelProject::GetPanelWidth()
{
    return m_nPanelWidth;
}