LAPTOP-T815PCOQ\25526
2024-11-21 07b2cefe6e0dfe8bc530aab3b58d4159502ceba8
SourceCode/Bond/BondEq/View/UserManagerDlg.cpp
@@ -25,6 +25,13 @@
CUserManagerDlg::~CUserManagerDlg()
{
   for (auto& pair : m_mapFonts) {
      if (pair.second) {
         pair.second->DeleteObject();
         delete pair.second;
      }
   }
   m_mapFonts.clear();
}
void CUserManagerDlg::DoDataExchange(CDataExchange* pDX)
@@ -342,6 +349,42 @@
   return false;
}
void CUserManagerDlg::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 CUserManagerDlg::AdjustControls(int nWidth, int nHeight)
{
   CWnd* pWnd = GetWindow(GW_CHILD);
@@ -361,10 +404,14 @@
      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 / 20);
         pGridCtrl->SetDefCellHeight(newHeight / 21);
         pGridCtrl->ExpandColumnsToFit(TRUE);
         pGridCtrl->Invalidate();
      }
@@ -382,27 +429,33 @@
   TCHAR szClassName[256];
   GetClassName(pWnd->m_hWnd, szClassName, sizeof(szClassName));
   if (_tcsicmp(szClassName, _T("Static")) == 0) {
      CStatic* pStatic = (CStatic*)pWnd;
      pStatic->ModifyStyle(0, SS_CENTER | SS_CENTERIMAGE);
      return;
   }
   // 跳过特殊控件(如 MFCGridCtrl)
   if (_tcsicmp(szClassName, _T("MFCGridCtrl")) == 0) {
      return;
   }
   int fontSize = nHeight - 10;
   CFont* pCurrentFont = pWnd->GetFont();
   LOGFONT logFont;
   pCurrentFont->GetLogFont(&logFont);
   logFont.lfHeight = -fontSize;
   // 根据控件高度动态调整字体大小
   int fontSize = nHeight / 2;
   if (fontSize < 8) fontSize = 8;
   CFont newFont;
   newFont.CreateFontIndirect(&logFont);
   // 检查字体是否已经存在
   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);
   pWnd->SetFont(&newFont);
   pWnd->Invalidate();
      // 存储到字体管理容器中
      m_mapFonts[fontSize] = newFont;
      it = m_mapFonts.find(fontSize);
   }
   pWnd->SetFont(it->second);
   pWnd->Invalidate(); // 刷新控件显示
}
BEGIN_MESSAGE_MAP(CUserManagerDlg, CDialogEx)
@@ -427,6 +480,9 @@
   SetWindowText(_T("用户管理"));
   SystemParametersInfo(SPI_GETWORKAREA, 0, &screenRect, 0);
   // 设置默认字体
   SetDefaultFont();
   GetClientRect(&clientRect);
   m_nInitialWidth = clientRect.Width();
   m_nInitialHeight = clientRect.Height();
@@ -436,7 +492,7 @@
   int dlgHeight = dlgRect.Height() * 3;
   if (dlgWidth > screenRect.Width()) {
      dlgWidth = screenRect.Width();
      dlgWidth = screenRect.Width();
   }
   if (dlgHeight > screenRect.Height()) {
      dlgHeight = screenRect.Height();