LAPTOP-SNT8I5JK\Boounion
2025-01-02 d362ec98ec0db2039944da31729ad8efcd72834a
SourceCode/Bond/BondEq/View/SystemLogManagerDlg.cpp
@@ -9,29 +9,20 @@
// CSystemLogManagerDlg 对话框
IMPLEMENT_DYNAMIC(CSystemLogManagerDlg, CDialogEx)
IMPLEMENT_DYNAMIC(CSystemLogManagerDlg, CBaseDlg)
CSystemLogManagerDlg::CSystemLogManagerDlg(CWnd* pParent /*=nullptr*/)
   : CDialogEx(IDD_DIALOG_SYSTEM_LOG_MANAGER, pParent)
   : CBaseDlg(IDD_DIALOG_SYSTEM_LOG_MANAGER, pParent)
{
   m_nInitialWidth = 0;
   m_nInitialHeight = 0;
}
CSystemLogManagerDlg::~CSystemLogManagerDlg()
{
   for (auto& pair : m_mapFonts) {
      if (pair.second) {
         pair.second->DeleteObject();
         delete pair.second;
      }
   }
   m_mapFonts.clear();
}
void CSystemLogManagerDlg::DoDataExchange(CDataExchange* pDX)
{
   CDialogEx::DoDataExchange(pDX);
   CBaseDlg::DoDataExchange(pDX);
   DDX_Control(pDX, IDC_COMBO_TYPE, m_comboType);
   DDX_Control(pDX, IDC_COMBO_USER, m_comboUser);
   DDX_Control(pDX, IDC_DATETIMEPICKER_START, m_dateTimeStart);
@@ -161,24 +152,6 @@
   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()
{
   // 格式化页码信息为 "当前页/总页数"
@@ -187,112 +160,13 @@
   m_staticPageNum.SetWindowText(pageInfo);
}
void CSystemLogManagerDlg::SetDefaultFont()
{
   CFont* defaultFont = GetOrCreateFont(12);
   // 遍历所有控件,应用默认字体
   CWnd* pWnd = GetWindow(GW_CHILD);
   while (pWnd) {
      // 跳过特殊控件(如 MFCGridCtrl)
      TCHAR szClassName[256];
      GetClassName(pWnd->m_hWnd, szClassName, sizeof(szClassName));
      if (_tcsicmp(szClassName, _T("MFCGridCtrl")) == 0) {
         pWnd = pWnd->GetNextWindow();
         continue;
      }
      pWnd->SetFont(defaultFont, TRUE);
      pWnd = pWnd->GetNextWindow();
   }
}
void CSystemLogManagerDlg::AdjustControls(float dScaleX, float dScaleY)
{
   CWnd* pWnd = GetWindow(GW_CHILD);
   while (pWnd) {
      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));
         TCHAR szClassName[256];
         GetClassName(pWnd->m_hWnd, szClassName, sizeof(szClassName));
         if (_tcsicmp(szClassName, _T("ComboBox")) == 0) {
            CComboBox* pComboBox = (CComboBox*)pWnd;
            pComboBox->SetItemHeight(-1, newRect.Height());  // -1 表示所有项的高度
         }
         if (_tcsicmp(szClassName, _T("MFCGridCtrl")) == 0) {
            CGridCtrl* pGridCtrl = (CGridCtrl*)pWnd;
            pGridCtrl->SetDefCellHeight(newRect.Height() / 21);
            pGridCtrl->ExpandColumnsToFit(TRUE);
            pGridCtrl->ExpandLastColumn();
            pGridCtrl->Invalidate();
            pGridCtrl->UpdateWindow();
         }
         pWnd->MoveWindow(&newRect);
         AdjustControlFont(pWnd, newRect.Width(), newRect.Height());
      }
      pWnd = pWnd->GetNextWindow();
   }
}
void CSystemLogManagerDlg::AdjustControlFont(CWnd* pWnd, int nWidth, int nHeight)
{
   TCHAR szClassName[256];
   GetClassName(pWnd->m_hWnd, szClassName, sizeof(szClassName));
   // 跳过特殊控件(如 MFCGridCtrl)
   if (_tcsicmp(szClassName, _T("MFCGridCtrl")) == 0) {
      return;
   }
   // 根据控件高度动态调整字体大小
   int fontSize = nHeight / 2;
   if (fontSize < 8) fontSize = 8;
   // 获取或创建字体
   CFont* pFont = GetOrCreateFont(fontSize);
   pWnd->SetFont(pFont);
   pWnd->Invalidate(); // 刷新控件显示
}
void CSystemLogManagerDlg::AdjustComboBoxStyle(CComboBox& comboBox)
{
   DWORD dwStyle = comboBox.GetStyle();
   comboBox.ModifyStyle(0, CBS_DROPDOWNLIST | CBS_HASSTRINGS | CBS_OWNERDRAWFIXED);
   comboBox.Invalidate();
   comboBox.UpdateWindow();
}
void CSystemLogManagerDlg::AdjustDateTimeCtrlStyle(CDateTimeCtrl& dateTimeCtrl)
{
   dateTimeCtrl.ModifyStyle(0, DTS_RIGHTALIGN);
   dateTimeCtrl.Invalidate();
   dateTimeCtrl.UpdateWindow();
}
BEGIN_MESSAGE_MAP(CSystemLogManagerDlg, CDialogEx)
BEGIN_MESSAGE_MAP(CSystemLogManagerDlg, CBaseDlg)
   ON_BN_CLICKED(IDC_BUTTON_SEARCH, &CSystemLogManagerDlg::OnBnClickedButtonSearch)
   ON_BN_CLICKED(IDC_BUTTON_PREV_PAGE, &CSystemLogManagerDlg::OnBnClickedButtonPrevPage)
   ON_BN_CLICKED(IDC_BUTTON_NEXT_PAGE, &CSystemLogManagerDlg::OnBnClickedButtonNextPage)
   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()
@@ -301,7 +175,7 @@
BOOL CSystemLogManagerDlg::OnInitDialog()
{
   CDialogEx::OnInitDialog();
   CBaseDlg::OnInitDialog();
   // TODO:  在此添加额外的初始化
   SetWindowText(_T("系统运行日志"));
@@ -330,88 +204,11 @@
   COleDateTime defaultStartTime = currentTime - COleDateTimeSpan(30, 0, 0, 0);
   m_dateTimeStart.SetTime(defaultStartTime);
   CRect screenRect, dlgRect, clientRect;
   GetClientRect(&clientRect);
   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;
   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);
   InitSystemLogManager();
   return TRUE;  // return TRUE unless you set the focus to a control
   // 异常: OCX 属性页应返回 FALSE
}
void CSystemLogManagerDlg::OnSize(UINT nType, int cx, int cy)
{
   CDialogEx::OnSize(nType, cx, cy);
   // TODO: 在此处添加消息处理程序代码
   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(dScaleX, dScaleY);
}
void CSystemLogManagerDlg::OnGetMinMaxInfo(MINMAXINFO* lpMMI)
{
   // TODO: 在此添加消息处理程序代码和/或调用默认值
   lpMMI->ptMinTrackSize.x = 400; // 最小宽度
   lpMMI->ptMinTrackSize.y = 300; // 最小高度
   CDialogEx::OnGetMinMaxInfo(lpMMI);
}
void CSystemLogManagerDlg::OnBnClickedButtonSearch()
{
@@ -426,7 +223,6 @@
      AfxMessageBox(errorMsg, MB_ICONERROR);
   }
}
void CSystemLogManagerDlg::OnBnClickedButtonPrevPage()
{
@@ -447,7 +243,6 @@
   }
}
void CSystemLogManagerDlg::OnBnClickedButtonNextPage()
{
   // TODO: 在此添加控件通知处理程序代码
@@ -467,7 +262,6 @@
   }
}
void CSystemLogManagerDlg::OnSelchangeComboType()
{
   // TODO: 在此添加控件通知处理程序代码
@@ -481,7 +275,6 @@
      AfxMessageBox(errorMsg, MB_ICONERROR);
   }
}
void CSystemLogManagerDlg::OnSelchangeComboUser()
{