diff --git a/TrafficMonitor/CommonData.cpp b/TrafficMonitor/CommonData.cpp index 49972eadb..0a8898265 100644 --- a/TrafficMonitor/CommonData.cpp +++ b/TrafficMonitor/CommonData.cpp @@ -3,6 +3,7 @@ #include "Common.h" #include "CalendarHelper.h" #include "TrafficMonitor.h" +#include "WindowsSettingHelper.h" /////////////////////////////////////////////////////////////////////////////////// int Date::week() const @@ -153,6 +154,40 @@ std::set& StringSet::data() return string_set; } +bool TaskBarSettingData::IsTaskbarTransparent() const +{ + if (CWindowsSettingHelper::IsWindows10LightTheme() || theApp.m_win_version.IsWindows8Or8point1() || theApp.m_is_windows11_taskbar) + return (transparent_color == back_color); + else + return transparent_color == 0; +} + +void TaskBarSettingData::SetTaskabrTransparent(bool transparent) +{ + if (transparent) + { + if (CWindowsSettingHelper::IsWindows10LightTheme() || theApp.m_win_version.IsWindows8Or8point1() || theApp.m_is_windows11_taskbar) + { + //浅色模式下要设置任务栏窗口透明,只需将透明色设置成和背景色一样即可 + CCommon::TransparentColorConvert(back_color); + transparent_color = back_color; + } + else + { + //深色模式下,背景色透明将透明色设置成黑色 + transparent_color = 0; + } + } + else + { + //要设置任务栏窗口不透明,只需将透明色设置成和背景色不一样即可 + if (back_color != TASKBAR_TRANSPARENT_COLOR1) + transparent_color = TASKBAR_TRANSPARENT_COLOR1; + else + transparent_color = TASKBAR_TRANSPARENT_COLOR2; + } +} + void TaskBarSettingData::ValidItemSpace() { if (item_space < 0) diff --git a/TrafficMonitor/CommonData.h b/TrafficMonitor/CommonData.h index 9083ea3d1..6a6e7afba 100644 --- a/TrafficMonitor/CommonData.h +++ b/TrafficMonitor/CommonData.h @@ -276,6 +276,8 @@ struct TaskBarSettingData : public PublicSettingData int light_default_style{ -1 }; //浅色主题时使用的预设方案 bool auto_set_background_color{ false }; //根据任务栏颜色自动设置背景色 bool auto_save_taskbar_color_settings_to_preset{}; //当启用“自动适应Windows10深色/浅色主题”时,是否在颜色设置有更改时自动将当前颜色设置保存到对应的预设 + bool IsTaskbarTransparent() const; + void SetTaskabrTransparent(bool transparent); CTaskbarItemOrderHelper item_order; unsigned int m_tbar_display_item{ TDI_UP | TDI_DOWN }; //任务栏窗口显示的项目 diff --git a/TrafficMonitor/TaskBarDlg.cpp b/TrafficMonitor/TaskBarDlg.cpp index 2d747d9ec..63aad5ff8 100644 --- a/TrafficMonitor/TaskBarDlg.cpp +++ b/TrafficMonitor/TaskBarDlg.cpp @@ -564,7 +564,7 @@ void CTaskBarDlg::MoveWindow(CRect rect) void CTaskBarDlg::DisableRenderFeatureIfNecessary(CSupportedRenderEnums& ref_supported_render_enums) { - bool is_transparent = CTaskbarDefaultStyle::IsTaskbarTransparent(theApp.m_taskbar_data); + bool is_transparent = theApp.m_taskbar_data.IsTaskbarTransparent(); // UpdateLayeredWindowIndirect失败则禁用D2D if (theApp.m_taskbar_data.update_layered_window_error_code) { diff --git a/TrafficMonitor/TaskBarSettingsDlg.cpp b/TrafficMonitor/TaskBarSettingsDlg.cpp index f69f5d89e..a27e848f6 100644 --- a/TrafficMonitor/TaskBarSettingsDlg.cpp +++ b/TrafficMonitor/TaskBarSettingsDlg.cpp @@ -90,7 +90,7 @@ void CTaskBarSettingsDlg::ApplyDefaultStyle(int index) theApp.m_taskbar_default_style.ApplyDefaultStyle(index, m_data); DrawStaticColor(); ((CButton*)GetDlgItem(IDC_SPECIFY_EACH_ITEM_COLOR_CHECK))->SetCheck(m_data.specify_each_item_color); - m_background_transparent_chk.SetCheck(IsTaskbarTransparent()); + m_background_transparent_chk.SetCheck(m_data.IsTaskbarTransparent()); } void CTaskBarSettingsDlg::ModifyDefaultStyle(int index) @@ -114,15 +114,6 @@ void CTaskBarSettingsDlg::EnableControl() //EnableDlgCtrl(IDC_TASKBAR_WND_SNAP_CHECK, theApp.m_win_version.IsWindows11OrLater() && !m_data.tbar_wnd_on_left); } -void CTaskBarSettingsDlg::SetTaskabrTransparent(bool transparent) -{ - CTaskbarDefaultStyle::SetTaskabrTransparent(transparent, m_data); -} - -bool CTaskBarSettingsDlg::IsTaskbarTransparent() -{ - return CTaskbarDefaultStyle::IsTaskbarTransparent(m_data); -} void CTaskBarSettingsDlg::SetControlMouseWheelEnable(bool enable) { @@ -277,7 +268,7 @@ BOOL CTaskBarSettingsDlg::OnInitDialog() } ((CButton*)GetDlgItem(IDC_HIDE_PERCENTAGE_CHECK))->SetCheck(m_data.hide_percent); ((CButton*)GetDlgItem(IDC_SPECIFY_EACH_ITEM_COLOR_CHECK))->SetCheck(m_data.specify_each_item_color); - m_background_transparent_chk.SetCheck(IsTaskbarTransparent()); + m_background_transparent_chk.SetCheck(m_data.IsTaskbarTransparent()); m_atuo_adapt_light_theme_chk.SetCheck(m_data.auto_adapt_light_theme); m_auto_set_back_color_chk.SetCheck(m_data.auto_set_background_color); m_auto_set_back_color_chk.EnableWindow(theApp.m_win_version.IsWindows8OrLater()); @@ -475,7 +466,7 @@ void CTaskBarSettingsDlg::OnOK() m_data.digits_number = m_digit_number_combo.GetCurSel() + 3; bool is_taskbar_transparent_checked = (m_background_transparent_chk.GetCheck() != 0); - SetTaskabrTransparent(is_taskbar_transparent_checked); + m_data.SetTaskabrTransparent(is_taskbar_transparent_checked); SaveColorSettingToDefaultStyle(); @@ -544,7 +535,7 @@ afx_msg LRESULT CTaskBarSettingsDlg::OnStaticClicked(WPARAM wParam, LPARAM lPara CMFCColorDialogEx colorDlg(m_data.back_color, 0, this); if (colorDlg.DoModal() == IDOK) { - bool background_transparent = IsTaskbarTransparent(); + bool background_transparent = m_data.IsTaskbarTransparent(); m_data.back_color = colorDlg.GetColor(); if (m_data.back_color == m_data.text_colors.begin()->second.label) MessageBox(CCommon::LoadText(IDS_SAME_BACK_TEXT_COLOR_WARNING), NULL, MB_ICONWARNING); @@ -701,7 +692,7 @@ void CTaskBarSettingsDlg::OnBnClickedBackgroundTransparentCheck() { // TODO: 在此添加控件通知处理程序代码 bool checked = (m_background_transparent_chk.GetCheck() != 0); - SetTaskabrTransparent(checked); + m_data.SetTaskabrTransparent(checked); m_style_modified = true; } diff --git a/TrafficMonitor/TaskBarSettingsDlg.h b/TrafficMonitor/TaskBarSettingsDlg.h index d2698eecb..60323155c 100644 --- a/TrafficMonitor/TaskBarSettingsDlg.h +++ b/TrafficMonitor/TaskBarSettingsDlg.h @@ -68,9 +68,6 @@ class CTaskBarSettingsDlg : public CTabDlg protected: void EnableControl(); - - void SetTaskabrTransparent(bool transparent); - bool IsTaskbarTransparent(); virtual void SetControlMouseWheelEnable(bool enable) override; virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 diff --git a/TrafficMonitor/TaskbarDefaultStyle.cpp b/TrafficMonitor/TaskbarDefaultStyle.cpp index b3af47b84..013a26ccf 100644 --- a/TrafficMonitor/TaskbarDefaultStyle.cpp +++ b/TrafficMonitor/TaskbarDefaultStyle.cpp @@ -110,40 +110,6 @@ void CTaskbarDefaultStyle::ModifyDefaultStyle(int index, TaskBarSettingData & da m_default_style[index].specify_each_item_color = data.specify_each_item_color; } -bool CTaskbarDefaultStyle::IsTaskbarTransparent(const TaskBarSettingData& data) -{ - if (CWindowsSettingHelper::IsWindows10LightTheme() || theApp.m_win_version.IsWindows8Or8point1() || theApp.m_is_windows11_taskbar) - return (data.transparent_color == data.back_color); - else - return data.transparent_color == 0; -} - -void CTaskbarDefaultStyle::SetTaskabrTransparent(bool transparent, TaskBarSettingData& data) -{ - if (transparent) - { - if (CWindowsSettingHelper::IsWindows10LightTheme() || theApp.m_win_version.IsWindows8Or8point1() || theApp.m_is_windows11_taskbar) - { - //浅色模式下要设置任务栏窗口透明,只需将透明色设置成和背景色一样即可 - CCommon::TransparentColorConvert(data.back_color); - data.transparent_color = data.back_color; - } - else - { - //深色模式下,背景色透明将透明色设置成黑色 - data.transparent_color = 0; - } - } - else - { - //要设置任务栏窗口不透明,只需将透明色设置成和背景色不一样即可 - if (data.back_color != TASKBAR_TRANSPARENT_COLOR1) - data.transparent_color = TASKBAR_TRANSPARENT_COLOR1; - else - data.transparent_color = TASKBAR_TRANSPARENT_COLOR2; - } -} - bool CTaskbarDefaultStyle::IsTaskBarStyleDataValid(const TaskBarStyleData& data) { for (const auto& item : data.text_colors) diff --git a/TrafficMonitor/TaskbarDefaultStyle.h b/TrafficMonitor/TaskbarDefaultStyle.h index 9010296ed..823e670dd 100644 --- a/TrafficMonitor/TaskbarDefaultStyle.h +++ b/TrafficMonitor/TaskbarDefaultStyle.h @@ -26,9 +26,6 @@ class CTaskbarDefaultStyle //static void ApplyDefaultLightStyle(TaskBarSettingData& data); //应用默认的浅色模式预设 void ModifyDefaultStyle(int index, TaskBarSettingData& data); //将当前颜色设置保存到一个预设方案 - static bool IsTaskbarTransparent(const TaskBarSettingData& data); - static void SetTaskabrTransparent(bool transparent, TaskBarSettingData& data); - static bool IsTaskBarStyleDataValid(const TaskBarStyleData& data); //判断一个颜色模式是否有效 private: diff --git a/TrafficMonitor/TrafficMonitor.cpp b/TrafficMonitor/TrafficMonitor.cpp index aaa4ce8e4..283a6f255 100644 --- a/TrafficMonitor/TrafficMonitor.cpp +++ b/TrafficMonitor/TrafficMonitor.cpp @@ -162,7 +162,7 @@ void CTrafficMonitorApp::LoadConfig() //任务栏窗口设置 m_taskbar_data.back_color = ini.GetInt(_T("task_bar"), _T("task_bar_back_color"), m_taskbar_data.dft_back_color); m_taskbar_data.transparent_color = ini.GetInt(_T("task_bar"), _T("transparent_color"), m_taskbar_data.dft_transparent_color); - if (CTaskbarDefaultStyle::IsTaskbarTransparent(m_taskbar_data)) //如果任务栏背景透明,则需要将颜色转换一下 + if (m_taskbar_data.IsTaskbarTransparent()) //如果任务栏背景透明,则需要将颜色转换一下 { CCommon::TransparentColorConvert(m_taskbar_data.back_color); CCommon::TransparentColorConvert(m_taskbar_data.transparent_color); diff --git a/TrafficMonitor/TrafficMonitorDlg.cpp b/TrafficMonitor/TrafficMonitorDlg.cpp index 2b06c21a3..f89d5a4f0 100644 --- a/TrafficMonitor/TrafficMonitorDlg.cpp +++ b/TrafficMonitor/TrafficMonitorDlg.cpp @@ -703,6 +703,7 @@ void CTrafficMonitorDlg::ApplySettings(COptionsDlg& optionsDlg) bool is_alow_out_of_border_changed = (optionsDlg.m_tab1_dlg.m_data.m_alow_out_of_border != theApp.m_main_wnd_data.m_alow_out_of_border); bool is_show_notify_icon_changed = (optionsDlg.m_tab3_dlg.m_data.show_notify_icon != theApp.m_general_data.show_notify_icon); bool is_connections_hide_changed = (optionsDlg.m_tab3_dlg.m_data.connections_hide.data() != theApp.m_general_data.connections_hide.data()); + bool d2d_turned_on = (theApp.m_taskbar_data.disable_d2d && !optionsDlg.m_tab2_dlg.m_data.disable_d2d); theApp.m_main_wnd_data = optionsDlg.m_tab1_dlg.m_data; theApp.m_taskbar_data = optionsDlg.m_tab2_dlg.m_data; @@ -713,6 +714,13 @@ void CTrafficMonitorDlg::ApplySettings(COptionsDlg& optionsDlg) SetTextFont(); + //打开了D2D渲染后自动开启“背景透明”并关闭“根据任务栏颜色自动设置背景色” + if (d2d_turned_on) + { + theApp.m_taskbar_data.SetTaskabrTransparent(true); + theApp.m_taskbar_data.auto_set_background_color = false; + } + //CTaskBarDlg::SaveConfig(); if (IsTaskbarWndValid()) { @@ -1617,10 +1625,10 @@ void CTrafficMonitorDlg::OnTimer(UINT_PTR nIDEvent) theApp.SaveConfig(); restart_taskbar_dlg = true; } - bool is_taskbar_transparent{ CTaskbarDefaultStyle::IsTaskbarTransparent(theApp.m_taskbar_data) }; + bool is_taskbar_transparent{ theApp.m_taskbar_data.IsTaskbarTransparent()}; if (!is_taskbar_transparent) { - CTaskbarDefaultStyle::SetTaskabrTransparent(false, theApp.m_taskbar_data); + theApp.m_taskbar_data.SetTaskabrTransparent(false); restart_taskbar_dlg = true; } if (restart_taskbar_dlg && IsTaskbarWndValid()) @@ -1698,9 +1706,9 @@ void CTrafficMonitorDlg::OnTimer(UINT_PTR nIDEvent) COLORREF color = ::GetPixel(m_desktop_dc, pointx, pointy); //取任务栏窗口左侧1像素处的颜色作为背景色 if (!CCommon::IsColorSimilar(color, theApp.m_taskbar_data.back_color) && (/*CWindowsSettingHelper::IsWindows10LightTheme() ||*/ color != 0)) { - bool is_taskbar_transparent{ CTaskbarDefaultStyle::IsTaskbarTransparent(theApp.m_taskbar_data) }; + bool is_taskbar_transparent{ theApp.m_taskbar_data.IsTaskbarTransparent()}; theApp.m_taskbar_data.back_color = color; - CTaskbarDefaultStyle::SetTaskabrTransparent(is_taskbar_transparent, theApp.m_taskbar_data); + theApp.m_taskbar_data.SetTaskabrTransparent(is_taskbar_transparent); if (is_taskbar_transparent) m_tBarDlg->ApplyWindowTransparentColor(); }