LAPTOP-T815PCOQ\25526
2024-12-23 89bcc7791c48d8bcf8e124e56849e44563f8097c
SourceCode/Bond/BondEq/CBaseDlg.cpp
@@ -9,10 +9,15 @@
CFont g_defaultFont;
Theme* g_currentTheme = &g_lightTheme;
// 全局资源句柄
HINSTANCE g_hCurrentResource = NULL;
IMPLEMENT_DYNAMIC(CBaseDlg, CDialogEx)
CBaseDlg::CBaseDlg(UINT id, CWnd* pPage) : CDialogEx(id, pPage), m_bResizing(false)
CBaseDlg::CBaseDlg(UINT nID, CWnd* pPage) : CDialogEx(nID, pPage), m_bResizing(false)
{
   m_nID = nID;
   m_pParent = pPage;
   m_nInitialWidth = 0;
   m_nInitialHeight = 0;
}
@@ -23,6 +28,57 @@
   m_mapFonts.clear();
   m_mapCtrlLayouts.clear();
   m_mapControls.clear();
}
void CBaseDlg::SwitchTheme(ThemeType enThemeType)
{
   // 使用 map 来根据 themeType 查找主题
   static const std::unordered_map<ThemeType, Theme*> themeMap = {
      { ThemeType::Light, &g_lightTheme },
      { ThemeType::Dark, &g_darkTheme }
   };
   // 设置当前主题
   auto it = themeMap.find(enThemeType);
   if (it != themeMap.end()) {
      g_currentTheme = it->second;
   }
   else {
      g_currentTheme = &g_lightTheme;
   }
   // 更新控件的外观
   CWnd* pWnd = GetWindow(GW_CHILD);
   while (pWnd) {
      pWnd->Invalidate();
      pWnd = pWnd->GetNextWindow();
   }
   // 更新对话框背景颜色
   SetBackgroundColor(g_currentTheme->backgroundColor);
}
void CBaseDlg::LoadResourceLibrary(const CString& strLanguage)
{
   // 卸载之前加载的资源库
   UnloadResourceLibrary();
   // 加载新的资源库
   g_hCurrentResource = AfxLoadLibrary(strLanguage);
   // 设置新的资源句柄
   if (g_hCurrentResource != NULL) {
      AfxSetResourceHandle(g_hCurrentResource);
   }
}
void CBaseDlg::UnloadResourceLibrary()
{
   // 卸载之前加载的资源库
   if (g_hCurrentResource != NULL) {
      FreeLibrary(g_hCurrentResource);   // 释放当前资源库
      g_hCurrentResource = NULL;         // 清空资源句柄
   }
}
CFont* CBaseDlg::GetOrCreateFont(int nFontSize)
@@ -104,34 +160,6 @@
      return it->second.get();
   }
   return nullptr;
}
void CBaseDlg::SwitchTheme(ThemeType themeType)
{
   // 使用 map 来根据 themeType 查找主题
   static const std::unordered_map<ThemeType, Theme*> themeMap = {
      { ThemeType::Light, &g_lightTheme },
      { ThemeType::Dark, &g_darkTheme }
   };
   // 设置当前主题
   auto it = themeMap.find(themeType);
   if (it != themeMap.end()) {
      g_currentTheme = it->second;
   }
   else {
      g_currentTheme = &g_lightTheme;
   }
   // 更新控件的外观
   CWnd* pWnd = GetWindow(GW_CHILD);
   while (pWnd) {
      pWnd->Invalidate(); // 重绘控件
      pWnd = pWnd->GetNextWindow();
   }
   // 更新对话框背景颜色
   SetBackgroundColor(g_currentTheme->backgroundColor);
}
void CBaseDlg::AdjustControls(float dScaleX, float dScaleY)