| | |
| | | CWnd* pWnd = GetWindow(GW_CHILD); |
| | | while (pWnd) { |
| | | int nCtrlID = pWnd->GetDlgCtrlID(); |
| | | if (nCtrlID != -1 && m_mapCtrlLayouts.find(nCtrlID) != m_mapCtrlLayouts.end()) |
| | | { |
| | | if (nCtrlID != -1 && m_mapCtrlLayouts.find(nCtrlID) != m_mapCtrlLayouts.end()) { |
| | | CRect originalRect = m_mapCtrlLayouts[nCtrlID]; |
| | | CRect newRect( |
| | | static_cast<int>(originalRect.left * dScaleX), |
| | |
| | | int colWidthLarge = availableWidth * 4 / 14; // 大宽度列比例 |
| | | int groupWidth = colWidthSmall * 2 + colWidthLarge; // 每组总宽度 |
| | | |
| | | for (int i = 0; i < m_nRowsPerPage; ++i) |
| | | { |
| | | for (int i = 0; i < m_nRowsPerPage; ++i) { |
| | | // 每一行的起始 Y 坐标 |
| | | int y = topMargin + i * (rowHeight + verticalSpacing); |
| | | |
| | | // 创建第 1 组 (0, 1, 2) |
| | | int x = sideMargin; // 从左边距开始 |
| | | CreateStaticControl(x, y, colWidthSmall, rowHeight, _T("OFF"), true); |
| | | CreateStaticControl(x, y, colWidthSmall, rowHeight, _T("OFF"), true, AlignCenter); |
| | | x += colWidthSmall; |
| | | CreateStaticControl(x, y, colWidthSmall, rowHeight, _T("X1000")); |
| | | CreateStaticControl(x, y, colWidthSmall, rowHeight, _T("X1000"), false, AlignCenter); |
| | | x += colWidthSmall; |
| | | CreateStaticControl(x, y, colWidthLarge, rowHeight, _T("描述文本"), false, true); |
| | | CreateStaticControl(x, y, colWidthLarge, rowHeight, _T("描述文本"), false); |
| | | |
| | | // 第 2 组起始位置,加上组间距 |
| | | x += colWidthLarge + groupSpacing; |
| | | |
| | | // 创建第 2 组 (3, 4, 5) |
| | | CreateStaticControl(x, y, colWidthSmall, rowHeight, _T("OFF"), true); |
| | | CreateStaticControl(x, y, colWidthSmall, rowHeight, _T("OFF"), true, AlignCenter); |
| | | x += colWidthSmall; |
| | | CreateStaticControl(x, y, colWidthSmall, rowHeight, _T("Y1010")); |
| | | CreateStaticControl(x, y, colWidthSmall, rowHeight, _T("Y1010"), false, AlignCenter); |
| | | x += colWidthSmall; |
| | | CreateStaticControl(x, y, colWidthLarge, rowHeight, _T("描述文本"), false, true); |
| | | CreateStaticControl(x, y, colWidthLarge, rowHeight, _T("描述文本"), false); |
| | | } |
| | | } |
| | | |
| | | void CIOMonitoringDlg::CreateStaticControl(int x, int y, int width, int height, const CString& text, bool hasBorder, bool alignLeft) |
| | | void CIOMonitoringDlg::CreateStaticControl(int x, int y, int width, int height, const CString& text, bool hasBorder, TextAlign alignment) |
| | | { |
| | | // 创建动态控件 |
| | | CBLLabel* pStatic = new CBLLabel(); |
| | | DWORD style = WS_CHILD | WS_VISIBLE | SS_CENTERIMAGE; // 确保垂直居中 |
| | | if (hasBorder) { |
| | | style |= WS_BORDER; // 添加边框 |
| | | style |= WS_BORDER; // 添加边框 |
| | | } |
| | | if (alignLeft) { |
| | | style |= SS_LEFT; // 左对齐文本 |
| | | } |
| | | else { |
| | | style |= SS_CENTER; // 居中文本 |
| | | } |
| | | |
| | | CStatic* pStatic = new CStatic(); |
| | | pStatic->Create(text, style, CRect(x, y, x + width, y + height), this); |
| | | |
| | | // 动态设置字体大小 |
| | | CFont* pFont = GetOrCreateFont(height / 3); |
| | | // 设置文本对齐方式 |
| | | pStatic->SetAlignment(alignment); |
| | | |
| | | // 设置动态字体调整,并设置字体大小(动态字体会根据控件大小调整) |
| | | int nSize = height / 3; |
| | | CFont* pFont = GetOrCreateFont(nSize); |
| | | pStatic->SetFont(pFont); |
| | | pStatic->SetFontSize(nSize); |
| | | pStatic->SetDynamicFont(TRUE); |
| | | |
| | | // 存储控件指针 |
| | | m_staticControls.push_back(pStatic); |
| | |
| | | // 显示控件并设置内容 |
| | | m_staticControls[row * m_nCols + 0]->SetWindowText(_T("OFF")); |
| | | m_staticControls[row * m_nCols + 0]->ShowWindow(SW_SHOW); |
| | | m_staticControls[row * m_nCols + 0]->SetBkColor(RGB(255, 0, 0)); |
| | | |
| | | m_staticControls[row * m_nCols + 1]->SetWindowText(CString(data.inputAddress.c_str())); |
| | | m_staticControls[row * m_nCols + 1]->ShowWindow(SW_SHOW); |
| | |
| | | |
| | | m_staticControls[row * m_nCols + 3]->SetWindowText(_T("OFF")); |
| | | m_staticControls[row * m_nCols + 3]->ShowWindow(SW_SHOW); |
| | | m_staticControls[row * m_nCols + 3]->SetBkColor(RGB(255, 0, 0)); |
| | | |
| | | m_staticControls[row * m_nCols + 4]->SetWindowText(CString(data.outputAddress.c_str())); |
| | | m_staticControls[row * m_nCols + 4]->ShowWindow(SW_SHOW); |
| | |
| | | } |
| | | else { |
| | | // 隐藏这一行的所有控件 |
| | | for (int col = 0; col < m_nCols; ++col) |
| | | { |
| | | for (int col = 0; col < m_nCols; ++col) { |
| | | m_staticControls[row * m_nCols + col]->ShowWindow(SW_HIDE); |
| | | } |
| | | } |
| | |
| | | |
| | | void CIOMonitoringDlg::ClearDynamicControls() |
| | | { |
| | | for (auto* pStatic : m_staticControls) |
| | | { |
| | | if (pStatic) |
| | | { |
| | | for (auto* pStatic : m_staticControls) { |
| | | if (pStatic) { |
| | | pStatic->DestroyWindow(); |
| | | delete pStatic; |
| | | } |