From 07b2cefe6e0dfe8bc530aab3b58d4159502ceba8 Mon Sep 17 00:00:00 2001
From: LAPTOP-T815PCOQ\25526 <mr.liuyang@126.com>
Date: 星期四, 21 十一月 2024 11:34:54 +0800
Subject: [PATCH] 1. 解决控件字体修改以后出现锯齿
---
SourceCode/Bond/BondEq/View/SystemLogManagerDlg.cpp | 214 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 208 insertions(+), 6 deletions(-)
diff --git a/SourceCode/Bond/BondEq/View/SystemLogManagerDlg.cpp b/SourceCode/Bond/BondEq/View/SystemLogManagerDlg.cpp
index 40e4492..004e2d8 100644
--- a/SourceCode/Bond/BondEq/View/SystemLogManagerDlg.cpp
+++ b/SourceCode/Bond/BondEq/View/SystemLogManagerDlg.cpp
@@ -5,8 +5,6 @@
#include "BondEq.h"
#include "afxdialogex.h"
#include "SystemLogManagerDlg.h"
-#include "UserManager.h"
-#include "SystemLogManager.h"
// CSystemLogManagerDlg 瀵硅瘽妗�
@@ -21,6 +19,13 @@
CSystemLogManagerDlg::~CSystemLogManagerDlg()
{
+ for (auto& pair : m_mapFonts) {
+ if (pair.second) {
+ pair.second->DeleteObject();
+ delete pair.second;
+ }
+ }
+ m_mapFonts.clear();
}
void CSystemLogManagerDlg::DoDataExchange(CDataExchange* pDX)
@@ -61,13 +66,13 @@
m_listLogs.SetFixedColumnCount(nFixCols);
// Col
- m_listLogs.SetColumnWidth(nColIdx, 20);
+ m_listLogs.SetColumnWidth(nColIdx, 10);
m_listLogs.SetItemText(nRowIdx, nColIdx++, _T("No."));
- m_listLogs.SetColumnWidth(nColIdx, 70);
+ m_listLogs.SetColumnWidth(nColIdx, 10);
m_listLogs.SetItemText(nRowIdx, nColIdx++, _T("绫诲瀷"));
- m_listLogs.SetColumnWidth(nColIdx, 150);
+ m_listLogs.SetColumnWidth(nColIdx, 200);
m_listLogs.SetItemText(nRowIdx, nColIdx++, _T("浜嬩欢"));
- m_listLogs.SetColumnWidth(nColIdx, 70);
+ m_listLogs.SetColumnWidth(nColIdx, 30);
m_listLogs.SetItemText(nRowIdx, nColIdx++, _T("鐢ㄦ埛"));
m_listLogs.SetColumnWidth(nColIdx, 70);
m_listLogs.SetItemText(nRowIdx, nColIdx++, _T("鏃堕棿"));
@@ -162,11 +167,141 @@
m_staticPageNum.SetWindowText(pageInfo);
}
+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; // 瀛樺偍鍒板瓧浣撶鐞嗗鍣�
+ }
+
+ // 閬嶅巻鎵�鏈夋帶浠讹紝搴旂敤榛樿瀛椾綋
+ 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(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 琛ㄧず鎵�鏈夐」鐨勯珮搴�
+ }
+
+ 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));
+
+ // 璺宠繃鐗规畩鎺т欢锛堝 MFCGridCtrl锛�
+ if (_tcsicmp(szClassName, _T("MFCGridCtrl")) == 0) {
+ return;
+ }
+
+ // 鏍规嵁鎺т欢楂樺害鍔ㄦ�佽皟鏁村瓧浣撳ぇ灏�
+ 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(); // 鍒锋柊鎺т欢鏄剧ず
+}
+
+
+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 +313,11 @@
CDialogEx::OnInitDialog();
// TODO: 鍦ㄦ娣诲姞棰濆鐨勫垵濮嬪寲
+ SetWindowText(_T("绯荤粺杩愯鏃ュ織"));
+
+ // 璁剧疆榛樿瀛椾綋
+ SetDefaultFont();
+
m_nCurrentPage = 1; // 浠庣涓�椤靛紑濮�
m_nTotalPages = 1; // 榛樿鎬婚〉鏁颁负 1
@@ -202,12 +342,45 @@
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());
+}
void CSystemLogManagerDlg::OnBnClickedButtonSearch()
@@ -264,3 +437,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