| | |
| | | CSystemLogManagerDlg::CSystemLogManagerDlg(CWnd* pParent /*=nullptr*/) |
| | | : CDialogEx(IDD_DIALOG_SYSTEM_LOG_MANAGER, pParent) |
| | | { |
| | | |
| | | m_nInitialWidth = 0; |
| | | m_nInitialHeight = 0; |
| | | } |
| | | |
| | | CSystemLogManagerDlg::~CSystemLogManagerDlg() |
| | |
| | | m_listLogs.SetItemText(nRowIdx, nColIdx++, _T("No.")); |
| | | m_listLogs.SetColumnWidth(nColIdx, 10); |
| | | m_listLogs.SetItemText(nRowIdx, nColIdx++, _T("类型")); |
| | | m_listLogs.SetColumnWidth(nColIdx, 200); |
| | | m_listLogs.SetColumnWidth(nColIdx, 100); |
| | | m_listLogs.SetItemText(nRowIdx, nColIdx++, _T("事件")); |
| | | m_listLogs.SetColumnWidth(nColIdx, 30); |
| | | m_listLogs.SetItemText(nRowIdx, nColIdx++, _T("用户")); |
| | | m_listLogs.SetColumnWidth(nColIdx, 70); |
| | | m_listLogs.SetColumnWidth(nColIdx, 50); |
| | | m_listLogs.SetItemText(nRowIdx, nColIdx++, _T("时间")); |
| | | |
| | | // 创建 20 行空白数据行 |
| | |
| | | } |
| | | } |
| | | |
| | | m_listLogs.Invalidate(); |
| | | m_listLogs.UpdateWindow(); |
| | | m_listLogs.ExpandColumnsToFit(FALSE); |
| | | m_listLogs.ExpandLastColumn(); |
| | | m_listLogs.Invalidate(); |
| | | m_listLogs.UpdateWindow(); |
| | | |
| | | UpdatePageInfo(); |
| | | } |
| | | |
| | | CFont* CSystemLogManagerDlg::GetOrCreateFont(int nFontSize) |
| | | { |
| | | auto it = m_mapFonts.find(nFontSize); |
| | | if (it != m_mapFonts.end()) { |
| | | return it->second; |
| | | } |
| | | |
| | | CFont* font = new CFont(); |
| | | LOGFONT logFont = { 0 }; |
| | | _tcscpy_s(logFont.lfFaceName, _T("Segoe UI")); |
| | | logFont.lfHeight = -nFontSize; |
| | | logFont.lfQuality = CLEARTYPE_QUALITY; |
| | | font->CreateFontIndirect(&logFont); |
| | | m_mapFonts[nFontSize] = font; |
| | | |
| | | return font; |
| | | } |
| | | |
| | | void CSystemLogManagerDlg::UpdatePageInfo() |
| | |
| | | |
| | | void CSystemLogManagerDlg::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; // 存储到字体管理容器 |
| | | } |
| | | CFont* defaultFont = GetOrCreateFont(12); |
| | | |
| | | // 遍历所有控件,应用默认字体 |
| | | CWnd* pWnd = GetWindow(GW_CHILD); |
| | |
| | | } |
| | | } |
| | | |
| | | void CSystemLogManagerDlg::AdjustControls(int nWidth, int nHeight) |
| | | void CSystemLogManagerDlg::AdjustControls(float dScaleX, float dScaleY) |
| | | { |
| | | CWnd* pWnd = GetWindow(GW_CHILD); |
| | | while (pWnd) { |
| | | UINT nCtrlID = pWnd->GetDlgCtrlID(); |
| | | int nCtrlID = pWnd->GetDlgCtrlID(); |
| | | if (nCtrlID != -1 && m_mapCtrlLayouts.find(nCtrlID) != m_mapCtrlLayouts.end()) |
| | | { |
| | | CRect originalRect = m_mapCtrlLayouts[nCtrlID]; |
| | | CRect newRect( |
| | | static_cast<int>(originalRect.left * dScaleX), |
| | | static_cast<int>(originalRect.top * dScaleY), |
| | | static_cast<int>(originalRect.right * dScaleX), |
| | | static_cast<int>(originalRect.bottom * dScaleY)); |
| | | |
| | | CRect ctrlRect; |
| | | pWnd->GetWindowRect(&ctrlRect); |
| | | ScreenToClient(&ctrlRect); |
| | | TCHAR szClassName[256]; |
| | | GetClassName(pWnd->m_hWnd, szClassName, sizeof(szClassName)); |
| | | |
| | | // 计算控件的新位置和大小,按比例调整 |
| | | 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)); |
| | | if (_tcsicmp(szClassName, _T("ComboBox")) == 0) { |
| | | CComboBox* pComboBox = (CComboBox*)pWnd; |
| | | pComboBox->SetItemHeight(-1, newRect.Height()); // -1 表示所有项的高度 |
| | | } |
| | | |
| | | TCHAR szClassName[256]; |
| | | GetClassName(pWnd->m_hWnd, szClassName, sizeof(szClassName)); |
| | | if (_tcsicmp(szClassName, _T("MFCGridCtrl")) == 0) { |
| | | CGridCtrl* pGridCtrl = (CGridCtrl*)pWnd; |
| | | pGridCtrl->SetDefCellHeight(newRect.Height() / 21); |
| | | pGridCtrl->ExpandColumnsToFit(TRUE); |
| | | pGridCtrl->ExpandLastColumn(); |
| | | pGridCtrl->Invalidate(); |
| | | pGridCtrl->UpdateWindow(); |
| | | } |
| | | |
| | | if (_tcsicmp(szClassName, _T("ComboBox")) == 0) { |
| | | CComboBox* pComboBox = (CComboBox*)pWnd; |
| | | pComboBox->SetItemHeight(-1, nHeight); // -1 表示所有项的高度 |
| | | pWnd->MoveWindow(&newRect); |
| | | AdjustControlFont(pWnd, newRect.Width(), newRect.Height()); |
| | | } |
| | | |
| | | if (_tcsicmp(szClassName, _T("MFCGridCtrl")) == 0) { |
| | | CGridCtrl* pGridCtrl = (CGridCtrl*)pWnd; |
| | | pGridCtrl->SetDefCellHeight(newHeight / 21); |
| | | pGridCtrl->ExpandColumnsToFit(TRUE); |
| | | pGridCtrl->Invalidate(); |
| | | } |
| | | |
| | | pWnd->MoveWindow(newX, newY, newWidth, newHeight); |
| | | AdjustControlFont(pWnd, newWidth, newHeight); |
| | | |
| | | // 获取下一个控件 |
| | | pWnd = pWnd->GetNextWindow(); |
| | | } |
| | | } |
| | |
| | | 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); |
| | | // 获取或创建字体 |
| | | CFont* pFont = GetOrCreateFont(fontSize); |
| | | |
| | | // 存储到字体管理容器中 |
| | | m_mapFonts[fontSize] = newFont; |
| | | it = m_mapFonts.find(fontSize); |
| | | } |
| | | |
| | | pWnd->SetFont(it->second); |
| | | pWnd->SetFont(pFont); |
| | | pWnd->Invalidate(); // 刷新控件显示 |
| | | } |
| | | |
| | |
| | | ON_CBN_SELCHANGE(IDC_COMBO_TYPE, &CSystemLogManagerDlg::OnSelchangeComboType) |
| | | ON_CBN_SELCHANGE(IDC_COMBO_USER, &CSystemLogManagerDlg::OnSelchangeComboUser) |
| | | ON_WM_SIZE() |
| | | ON_WM_GETMINMAXINFO() |
| | | END_MESSAGE_MAP() |
| | | |
| | | |
| | |
| | | |
| | | // TODO: 在此添加额外的初始化 |
| | | SetWindowText(_T("系统运行日志")); |
| | | |
| | | // 设置默认字体 |
| | | SetDefaultFont(); |
| | | |
| | | m_nCurrentPage = 1; // 从第一页开始 |
| | | m_nTotalPages = 1; // 默认总页数为 1 |
| | |
| | | m_nInitialWidth = clientRect.Width(); |
| | | m_nInitialHeight = clientRect.Height(); |
| | | |
| | | // 初始化默认字体 |
| | | CFont* pDefaultFont = GetOrCreateFont(12); |
| | | |
| | | // 遍历所有子控件,记录初始位置并设置默认字体 |
| | | CWnd* pWnd = GetWindow(GW_CHILD); |
| | | while (pWnd) { |
| | | int nCtrlID = pWnd->GetDlgCtrlID(); |
| | | if (nCtrlID != -1) { |
| | | // 记录控件初始布局 |
| | | CRect ctrlRect; |
| | | pWnd->GetWindowRect(&ctrlRect); |
| | | ScreenToClient(&ctrlRect); |
| | | m_mapCtrlLayouts[nCtrlID] = ctrlRect; |
| | | |
| | | // 跳过特殊控件(如 MFCGridCtrl) |
| | | TCHAR szClassName[256]; |
| | | GetClassName(pWnd->m_hWnd, szClassName, sizeof(szClassName)); |
| | | if (_tcsicmp(szClassName, _T("MFCGridCtrl")) == 0) { |
| | | pWnd = pWnd->GetNextWindow(); |
| | | continue; |
| | | } |
| | | |
| | | // 设置默认字体 |
| | | pWnd->SetFont(pDefaultFont); |
| | | } |
| | | pWnd = pWnd->GetNextWindow(); |
| | | } |
| | | |
| | | GetWindowRect(&dlgRect); |
| | | int dlgWidth = dlgRect.Width() * 2; |
| | | int dlgHeight = dlgRect.Height() * 2; |
| | |
| | | CDialogEx::OnSize(nType, cx, cy); |
| | | |
| | | // TODO: 在此处添加消息处理程序代码 |
| | | CRect rect; |
| | | GetClientRect(&rect); |
| | | if (nType == SIZE_MINIMIZED || m_mapCtrlLayouts.empty()) { |
| | | return; |
| | | } |
| | | |
| | | float dScaleX = static_cast<float>(cx) / m_nInitialWidth; |
| | | float dScaleY = static_cast<float>(cy) / m_nInitialHeight; |
| | | |
| | | // 遍历对话框中的所有控件 |
| | | AdjustControls(rect.Width(), rect.Height()); |
| | | AdjustControls(dScaleX, dScaleY); |
| | | } |
| | | |
| | | |
| | | void CSystemLogManagerDlg::OnGetMinMaxInfo(MINMAXINFO* lpMMI) |
| | | { |
| | | // TODO: 在此添加消息处理程序代码和/或调用默认值 |
| | | lpMMI->ptMinTrackSize.x = 400; // 最小宽度 |
| | | lpMMI->ptMinTrackSize.y = 300; // 最小高度 |
| | | |
| | | CDialogEx::OnGetMinMaxInfo(lpMMI); |
| | | } |
| | | |
| | | |