From d184fb507b475e2ba29cbd91b7e615fa59a9b1f6 Mon Sep 17 00:00:00 2001
From: LAPTOP-T815PCOQ\25526 <mr.liuyang@126.com>
Date: 星期四, 21 十一月 2024 10:18:26 +0800
Subject: [PATCH] 1.对系统运行日志管理类优化,比如获取单例模式的方式。unique_ptr必须通过析构函数结束
---
SourceCode/Bond/BondEq/View/SystemLogManagerDlg.cpp | 183 +++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 183 insertions(+), 0 deletions(-)
diff --git a/SourceCode/Bond/BondEq/View/SystemLogManagerDlg.cpp b/SourceCode/Bond/BondEq/View/SystemLogManagerDlg.cpp
index 40e4492..db8da77 100644
--- a/SourceCode/Bond/BondEq/View/SystemLogManagerDlg.cpp
+++ b/SourceCode/Bond/BondEq/View/SystemLogManagerDlg.cpp
@@ -162,11 +162,129 @@
m_staticPageNum.SetWindowText(pageInfo);
}
+void CSystemLogManagerDlg::SetDefaultFont()
+{
+ CFont* pFont = new CFont();
+ LOGFONT logFont = { 0 };
+
+ // 璁剧疆瀛椾綋灞炴��
+ _tcscpy_s(logFont.lfFaceName, _T("Segoe UI")); // 浣跨敤娓呮櫚瀛椾綋
+ logFont.lfHeight = -12; // 瀛椾綋楂樺害
+ logFont.lfWeight = FW_NORMAL;
+ logFont.lfQuality = CLEARTYPE_QUALITY; // 鍚敤 ClearType 鎶楅敮榻�
+
+ pFont->CreateFontIndirect(&logFont);
+
+ // 閬嶅巻鎵�鏈夋帶浠讹紝搴旂敤瀛椾綋
+ CWnd* pWnd = GetWindow(GW_CHILD);
+ while (pWnd) {
+ TCHAR szClassName[256];
+ GetClassName(pWnd->m_hWnd, szClassName, sizeof(szClassName));
+ if (_tcsicmp(szClassName, _T("MFCGridCtrl")) == 0
+ || _tcsicmp(szClassName, _T("ComboBoxs")) == 0) {
+ pWnd = pWnd->GetNextWindow();
+ continue;
+ }
+
+ pWnd->SetFont(pFont, TRUE);
+ pWnd = pWnd->GetNextWindow();
+ }
+}
+
+void CSystemLogManagerDlg::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("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();
+ }
+}
+
+void CSystemLogManagerDlg::AdjustControlFont(CWnd* pWnd, int nWidth, int nHeight)
+{
+ TCHAR szClassName[256];
+ GetClassName(pWnd->m_hWnd, szClassName, sizeof(szClassName));
+
+ if (_tcsicmp(szClassName, _T("Static")) == 0) {
+ CStatic* pStatic = (CStatic*)pWnd;
+ pStatic->ModifyStyle(SS_CENTER | SS_RIGHT | SS_CENTERIMAGE, SS_LEFT | SS_CENTERIMAGE);
+ return;
+ }
+
+ if (_tcsicmp(szClassName, _T("ComboBox")) == 0) {
+ CComboBox* pComboBox = (CComboBox*)pWnd;
+ pComboBox->SetItemHeight(-1, nHeight); // -1 琛ㄧず鎵�鏈夐」鐨勯珮搴�
+ }
+
+ if (_tcsicmp(szClassName, _T("MFCGridCtrl")) == 0) {
+ return;
+ }
+
+ int fontSize = nHeight - 10;
+ CFont* pCurrentFont = pWnd->GetFont();
+ LOGFONT logFont;
+ pCurrentFont->GetLogFont(&logFont);
+ logFont.lfHeight = -fontSize;
+
+ CFont newFont;
+ newFont.CreateFontIndirect(&logFont);
+
+ pWnd->SetFont(&newFont);
+ 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)
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()
END_MESSAGE_MAP()
@@ -178,6 +296,8 @@
CDialogEx::OnInitDialog();
// TODO: 鍦ㄦ娣诲姞棰濆鐨勫垵濮嬪寲
+ SetWindowText(_T("绯荤粺杩愯鏃ュ織"));
+
m_nCurrentPage = 1; // 浠庣涓�椤靛紑濮�
m_nTotalPages = 1; // 榛樿鎬婚〉鏁颁负 1
@@ -202,12 +322,46 @@
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();
+
+ 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: 鍦ㄦ澶勬坊鍔犳秷鎭鐞嗙▼搴忎唬鐮�
+ CRect rect;
+ GetClientRect(&rect);
+
+ // 閬嶅巻瀵硅瘽妗嗕腑鐨勬墍鏈夋帶浠�
+ AdjustControls(rect.Width(), rect.Height());
+ //SetDefaultFont();
+}
void CSystemLogManagerDlg::OnBnClickedButtonSearch()
@@ -264,3 +418,32 @@
}
}
+
+void CSystemLogManagerDlg::OnSelchangeComboType()
+{
+ // TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
+ try {
+ m_nCurrentPage = 1;
+ FillSystemLogManager();
+ }
+ catch (const std::exception& ex) {
+ CString errorMsg;
+ errorMsg.Format(_T("鍒囨崲绫诲瀷澶辫触锛�%s"), CString(ex.what()));
+ AfxMessageBox(errorMsg, MB_ICONERROR);
+ }
+}
+
+
+void CSystemLogManagerDlg::OnSelchangeComboUser()
+{
+ // TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
+ try {
+ m_nCurrentPage = 1;
+ FillSystemLogManager();
+ }
+ catch (const std::exception& ex) {
+ CString errorMsg;
+ errorMsg.Format(_T("鍒囨崲瑙掕壊澶辫触锛�%s"), CString(ex.what()));
+ AfxMessageBox(errorMsg, MB_ICONERROR);
+ }
+}
\ No newline at end of file
--
Gitblit v1.9.3