LAPTOP-T815PCOQ\25526
2024-11-21 07b2cefe6e0dfe8bc530aab3b58d4159502ceba8
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
// AxisSettingsDlg.cpp: 实现文件
//
 
#include "stdafx.h"
#include "BondEq.h"
#include "afxdialogex.h"
#include "AxisSettingsDlg.h"
 
 
// CAxisSettingsDlg 对话框
 
IMPLEMENT_DYNAMIC(CAxisSettingsDlg, CDialogEx)
 
CAxisSettingsDlg::CAxisSettingsDlg(CWnd* pParent /*=nullptr*/)
    : CDialogEx(IDD_DIALOG_AXIS_SETTINGS, pParent)
{
    m_nInitialWidth = 0;
    m_nInitialHeight = 0;
}
 
CAxisSettingsDlg::~CAxisSettingsDlg()
{
    for (auto& pair : m_mapFonts) {
        if (pair.second) {
            pair.second->DeleteObject();
            delete pair.second;
        }
    }
    m_mapFonts.clear();
}
 
void CAxisSettingsDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialogEx::DoDataExchange(pDX);
}
 
void CAxisSettingsDlg::SetDefaultFont()
{
    CFont* defaultFont = nullptr;
 
    // 如果字体管理容器中有默认大小(如 12)的字体,直接使用
    auto it = m_mapFonts.find(12);
    if (it != m_mapFonts.end()) {
        defaultFont = it->second;
    }
    else {
        // 创建默认字体
        defaultFont = new CFont();
        LOGFONT logFont = { 0 };
        _tcscpy_s(logFont.lfFaceName, _T("Segoe UI"));
        logFont.lfHeight = -12;
        logFont.lfQuality = CLEARTYPE_QUALITY;
        defaultFont->CreateFontIndirect(&logFont);
        m_mapFonts[12] = defaultFont; // 存储到字体管理容器
    }
 
    // 遍历所有控件,应用默认字体
    CWnd* pWnd = GetWindow(GW_CHILD);
    while (pWnd) {
        pWnd->SetFont(defaultFont, TRUE);
        pWnd = pWnd->GetNextWindow();
    }
}
 
void CAxisSettingsDlg::AdjustControls(int nWidth, int nHeight)
{
    CWnd* pWnd = GetWindow(GW_CHILD);
    while (pWnd) {
        UINT nCtrlID = pWnd->GetDlgCtrlID();
 
        CRect ctrlRect;
        pWnd->GetWindowRect(&ctrlRect);
        ScreenToClient(&ctrlRect);
 
        // 计算控件的新位置和大小,按比例调整
        int newX = (int)(ctrlRect.left * (nWidth / (float)m_nInitialWidth));
        int newY = (int)(ctrlRect.top * (nHeight / (float)m_nInitialHeight));
        int newWidth = (int)(ctrlRect.Width() * (nWidth / (float)m_nInitialWidth));
        int newHeight = (int)(ctrlRect.Height() * (nHeight / (float)m_nInitialHeight));
 
        TCHAR szClassName[256];
        GetClassName(pWnd->m_hWnd, szClassName, sizeof(szClassName));
 
        if (_tcsicmp(szClassName, _T("ComboBox")) == 0) {
            CComboBox* pComboBox = (CComboBox*)pWnd;
            pComboBox->SetItemHeight(-1, nHeight);  // -1 表示所有项的高度
        }
 
        pWnd->MoveWindow(newX, newY, newWidth, newHeight);
        AdjustControlFont(pWnd, newWidth, newHeight);
 
        // 获取下一个控件
        pWnd = pWnd->GetNextWindow();
    }
}
 
void CAxisSettingsDlg::AdjustControlFont(CWnd* pWnd, int nWidth, int nHeight)
{
    // 根据控件高度动态调整字体大小
    int fontSize = nHeight / 2;
    if (fontSize < 8) fontSize = 8;
 
    // 检查字体是否已经存在
    auto it = m_mapFonts.find(fontSize);
    if (it == m_mapFonts.end()) {
        // 动态创建新字体
        CFont* newFont = new CFont();
        LOGFONT logFont = { 0 };
        _tcscpy_s(logFont.lfFaceName, _T("Segoe UI"));
        logFont.lfHeight = -fontSize;
        logFont.lfQuality = CLEARTYPE_QUALITY; // 启用 ClearType 抗锯齿
        newFont->CreateFontIndirect(&logFont);
 
        // 存储到字体管理容器中
        m_mapFonts[fontSize] = newFont;
        it = m_mapFonts.find(fontSize);
    }
 
    pWnd->SetFont(it->second);
    pWnd->Invalidate(); // 刷新控件显示
}
 
 
BEGIN_MESSAGE_MAP(CAxisSettingsDlg, CDialogEx)
    ON_BN_CLICKED(IDC_BUTTON_AXIS_LAST, &CAxisSettingsDlg::OnBnClickedButtonAxisLast)
    ON_BN_CLICKED(IDC_BUTTON_AXIS_NEXT, &CAxisSettingsDlg::OnBnClickedButtonAxisNext)
    ON_BN_CLICKED(IDC_BUTTON_AXIS_ANCHOR_POINT_GROUP1, &CAxisSettingsDlg::OnBnClickedButtonAxisAnchorPointGroup1)
    ON_BN_CLICKED(IDC_BUTTON_AXIS_ANCHOR_POINT_GROUP2, &CAxisSettingsDlg::OnBnClickedButtonAxisAnchorPointGroup2)
    ON_BN_CLICKED(IDC_BUTTON_AXIS_ANCHOR_POINT_GROUP3, &CAxisSettingsDlg::OnBnClickedButtonAxisAnchorPointGroup3)
    ON_BN_CLICKED(IDC_BUTTON_AXIS_ANCHOR_POINT_GROUP4, &CAxisSettingsDlg::OnBnClickedButtonAxisAnchorPointGroup4)
    ON_BN_CLICKED(IDC_BUTTON_AXIS_ANCHOR_POINT_GROUP5, &CAxisSettingsDlg::OnBnClickedButtonAxisAnchorPointGroup5)
    ON_BN_CLICKED(IDC_BUTTON_AXIS_ANCHOR_POINT1, &CAxisSettingsDlg::OnBnClickedButtonAxisAnchorPoint1)
    ON_BN_CLICKED(IDC_BUTTON_AXIS_ANCHOR_POINT2, &CAxisSettingsDlg::OnBnClickedButtonAxisAnchorPoint2)
    ON_BN_CLICKED(IDC_BUTTON_AXIS_ANCHOR_POINT3, &CAxisSettingsDlg::OnBnClickedButtonAxisAnchorPoint3)
    ON_BN_CLICKED(IDC_BUTTON_AXIS_ANCHOR_POINT4, &CAxisSettingsDlg::OnBnClickedButtonAxisAnchorPoint4)
    ON_BN_CLICKED(IDC_BUTTON_AXIS_ANCHOR_POINT5, &CAxisSettingsDlg::OnBnClickedButtonAxisAnchorPoint5)
    ON_BN_CLICKED(IDC_BUTTON_AXIS_TEST_OPR, &CAxisSettingsDlg::OnBnClickedButtonAxisTestOpr)
    ON_BN_CLICKED(IDC_BUTTON_AXIS_TEST_JOG_ADD, &CAxisSettingsDlg::OnBnClickedButtonAxisTestJogAdd)
    ON_BN_CLICKED(IDC_BUTTON_AXIS_TEST_JOG_SUB, &CAxisSettingsDlg::OnBnClickedButtonAxisTestJogSub)
    ON_BN_CLICKED(IDC_BUTTON_AXIS_TEST_STOP, &CAxisSettingsDlg::OnBnClickedButtonAxisTestStop)
    ON_WM_SIZE()
    ON_WM_CTLCOLOR()
    ON_WM_SIZING()
END_MESSAGE_MAP()
 
 
// CAxisSettingsDlg 消息处理程序
 
 
BOOL CAxisSettingsDlg::OnInitDialog()
{
    CDialogEx::OnInitDialog();
 
    // TODO:  在此添加额外的初始化
    //ModifyStyle(0, WS_THICKFRAME | WS_SIZEBOX);
 
    // 设置默认字体
    SetDefaultFont();
 
    CRect screenRect, dlgRect, clientRect;
    GetClientRect(&clientRect);
    m_nInitialWidth = clientRect.Width();
    m_nInitialHeight = clientRect.Height();
 
    GetWindowRect(&dlgRect);
    int dlgWidth = dlgRect.Width() * 2;
    int dlgHeight = dlgRect.Height() * 2;
 
    SystemParametersInfo(SPI_GETWORKAREA, 0, &screenRect, 0);
    if (dlgWidth > screenRect.Width()) {
        dlgWidth = screenRect.Width();
    }
    if (dlgHeight > screenRect.Height()) {
        dlgHeight = screenRect.Height();
    }
 
    int centerX = screenRect.left + (screenRect.Width() - dlgWidth) / 2;
    int centerY = screenRect.top + (screenRect.Height() - dlgHeight) / 2;
    MoveWindow(centerX, centerY, dlgWidth, dlgHeight);
 
    return TRUE;  // return TRUE unless you set the focus to a control
    // 异常: OCX 属性页应返回 FALSE
}
 
void CAxisSettingsDlg::OnSize(UINT nType, int cx, int cy)
{
    CDialogEx::OnSize(nType, cx, cy);
 
    // TODO: 在此处添加消息处理程序代码
    CRect rect;
    GetClientRect(&rect);
 
    // 遍历对话框中的所有控件
    AdjustControls(rect.Width(), rect.Height());
}
 
void CAxisSettingsDlg::OnSizing(UINT fwSide, LPRECT pRect)
{
    if (fwSide == WMSZ_BOTTOMRIGHT) {
        if (pRect->right - pRect->left < 200) {
            pRect->right = pRect->left + 200;
        }
        if (pRect->bottom - pRect->top < 150) {
            pRect->bottom = pRect->top + 150;
        }
    }
 
    CDialogEx::OnSizing(fwSide, pRect);
}
 
HBRUSH CAxisSettingsDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
    HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor);
 
    // TODO:  在此更改 DC 的任何特性
 
    // TODO:  如果默认的不是所需画笔,则返回另一个画笔
    return hbr;
}
 
void CAxisSettingsDlg::OnBnClickedButtonAxisLast()
{
    // TODO: 在此添加控件通知处理程序代码
}
 
void CAxisSettingsDlg::OnBnClickedButtonAxisNext()
{
    // TODO: 在此添加控件通知处理程序代码
}
 
void CAxisSettingsDlg::OnBnClickedButtonAxisAnchorPointGroup1()
{
    // TODO: 在此添加控件通知处理程序代码
}
 
void CAxisSettingsDlg::OnBnClickedButtonAxisAnchorPointGroup2()
{
    // TODO: 在此添加控件通知处理程序代码
}
 
void CAxisSettingsDlg::OnBnClickedButtonAxisAnchorPointGroup3()
{
    // TODO: 在此添加控件通知处理程序代码
}
 
void CAxisSettingsDlg::OnBnClickedButtonAxisAnchorPointGroup4()
{
    // TODO: 在此添加控件通知处理程序代码
}
 
void CAxisSettingsDlg::OnBnClickedButtonAxisAnchorPointGroup5()
{
    // TODO: 在此添加控件通知处理程序代码
}
 
void CAxisSettingsDlg::OnBnClickedButtonAxisAnchorPoint1()
{
    // TODO: 在此添加控件通知处理程序代码
}
 
void CAxisSettingsDlg::OnBnClickedButtonAxisAnchorPoint2()
{
    // TODO: 在此添加控件通知处理程序代码
}
 
void CAxisSettingsDlg::OnBnClickedButtonAxisAnchorPoint3()
{
    // TODO: 在此添加控件通知处理程序代码
}
 
void CAxisSettingsDlg::OnBnClickedButtonAxisAnchorPoint4()
{
    // TODO: 在此添加控件通知处理程序代码
}
 
void CAxisSettingsDlg::OnBnClickedButtonAxisAnchorPoint5()
{
    // TODO: 在此添加控件通知处理程序代码
}
 
void CAxisSettingsDlg::OnBnClickedButtonAxisTestOpr()
{
    // TODO: 在此添加控件通知处理程序代码
}
 
void CAxisSettingsDlg::OnBnClickedButtonAxisTestJogAdd()
{
    // TODO: 在此添加控件通知处理程序代码
}
 
void CAxisSettingsDlg::OnBnClickedButtonAxisTestJogSub()
{
    // TODO: 在此添加控件通知处理程序代码
}
 
void CAxisSettingsDlg::OnBnClickedButtonAxisTestStop()
{
    // TODO: 在此添加控件通知处理程序代码
}