Skip to content

Commit

Permalink
任务栏设置中win11相关设置移动到单独的对话框中;增加避免与右侧小组件重叠的选项
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongyang219 committed Jan 25, 2025
1 parent 25a7ca7 commit 5f18357
Show file tree
Hide file tree
Showing 11 changed files with 177 additions and 63 deletions.
3 changes: 2 additions & 1 deletion TrafficMonitor/CommonData.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ struct MainConfigData
bool m_sunday_first{ true }; //是否将周日作为一周的第一天
StringSet plugin_disabled; //已禁用的插件

int taskbar_left_space_win11{}; //Windows11下,任务栏窗口显示在左侧时的边距
};

//内存显示方式
Expand Down Expand Up @@ -305,6 +304,8 @@ struct TaskBarSettingData : public PublicSettingData
void ValidVerticalMargin();
void ValidWindowOffsetTop();
void ValidWindowOffsetLeft();
bool avoid_overlap_with_widgets{ false }; //避免与右侧小组件重叠
int taskbar_left_space_win11{}; //Windows11下,任务栏小工具的宽度

bool show_netspeed_figure{ false }; //是否显示网速占用图
int netspeed_figure_max_value; //网速占用图的最大值
Expand Down
22 changes: 9 additions & 13 deletions TrafficMonitor/TaskBarDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -670,11 +670,11 @@ bool CTaskBarDlg::AdjustWindowPos()
//靠近通知区的情况
else
{
////如果显示了小组件,并且任务栏靠左显示,则留出小组件的位置(Win11 build 25324之后小组件显示在右侧)
//if (CWindowsSettingHelper::IsTaskbarWidgetsBtnShown() && !CWindowsSettingHelper::IsTaskbarCenterAlign() && theApp.m_win_version.GetBuildNumber() >= 25324)
// m_rect.MoveToX(m_rcNotify.left - m_rect.Width() + 2 - DPI(theApp.m_cfg_data.taskbar_left_space_win11));
//else
m_rect.MoveToX(m_rcNotify.left - m_rect.Width() + 2);
//如果显示了小组件,并且任务栏靠左显示,则留出小组件的位置
if (theApp.m_taskbar_data.avoid_overlap_with_widgets && CWindowsSettingHelper::IsTaskbarWidgetsBtnShown() && !CWindowsSettingHelper::IsTaskbarCenterAlign())
m_rect.MoveToX(m_rcNotify.left - m_rect.Width() + 2 - DPI(theApp.m_taskbar_data.taskbar_left_space_win11));
else
m_rect.MoveToX(m_rcNotify.left - m_rect.Width() + 2);
}
}
else
Expand Down Expand Up @@ -702,7 +702,7 @@ bool CTaskBarDlg::AdjustWindowPos()
else
{
if (CWindowsSettingHelper::IsTaskbarWidgetsBtnShown())
m_rect.MoveToX(2 + DPI(theApp.m_cfg_data.taskbar_left_space_win11));
m_rect.MoveToX(2 + DPI(theApp.m_taskbar_data.taskbar_left_space_win11));
else
m_rect.MoveToX(2);
}
Expand Down Expand Up @@ -1259,14 +1259,10 @@ bool CTaskBarDlg::IsShowNetSpeed()

bool CTaskBarDlg::IsTaskbarCloseToIconEnable(bool taskbar_wnd_on_left)
{
//在Windows11 24H2中,当任务栏窗口显示在右侧时,如果勾选“任务栏窗口靠近图标而不是靠近任务栏窗口”会导致和图标重叠
//因为"MSTaskSwWClass"窗口的矩形区域不再是任务栏图标最小化按钮所在区域,我不清楚具体是从Windows11哪个版本开始变成这样的,
//猜测是在增加了“不合并任务栏按钮并隐藏标签”这个功能之后开始的,也就是build 23466版本,
//因此这里判断当只有23466以前的版本允许这个选项
//在Windows11中,当任务栏窗口显示在右侧时,如果勾选“任务栏窗口靠近图标而不是靠近任务栏窗口”会导致和图标重叠
//因为"MSTaskSwWClass"窗口的矩形区域不再是任务栏图标最小化按钮所在区域
return theApp.m_win_version.IsWindows11OrLater() &&
((theApp.m_win_version.GetBuildNumber() < 23466)
|| (CWindowsSettingHelper::IsTaskbarCenterAlign() && taskbar_wnd_on_left)
);
CWindowsSettingHelper::IsTaskbarCenterAlign() && taskbar_wnd_on_left;
}

std::wstring CTaskBarDlg::GetTaskbarDebugString() const
Expand Down
47 changes: 9 additions & 38 deletions TrafficMonitor/TaskBarSettingsDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "WindowsSettingHelper.h"
#include "TrafficMonitorDlg.h"
#include "FileDialogEx.h"
#include "Win11TaskbarSettingDlg.h"

// CTaskBarSettingsDlg 对话框

Expand Down Expand Up @@ -112,11 +113,10 @@ void CTaskBarSettingsDlg::EnableControl()
EnableDlgCtrl(IDC_CM_GRAPH_PLOT_RADIO, m_data.show_status_bar || m_data.show_netspeed_figure);
EnableDlgCtrl(IDC_NET_SPEED_FIGURE_MAX_VALUE_EDIT, m_data.show_netspeed_figure);
EnableDlgCtrl(IDC_NET_SPEED_FIGURE_MAX_VALUE_UNIT_COMBO, m_data.show_netspeed_figure);
bool taskbar_on_left_check = (IsDlgButtonChecked(IDC_TASKBAR_WND_ON_LEFT_CHECK) != FALSE);
EnableDlgCtrl(IDC_TASKBAR_WND_SNAP_CHECK, CTaskBarDlg::IsTaskbarCloseToIconEnable(taskbar_on_left_check));
//Win11下,任务栏左对齐时禁用“任务栏窗口显示在任务栏左侧”的选项
EnableDlgCtrl(IDC_TASKBAR_WND_ON_LEFT_CHECK, !theApp.m_is_windows11_taskbar || CWindowsSettingHelper::IsTaskbarCenterAlign());
EnableDlgCtrl(IDC_ENABLE_COLOR_EMOJI_CHECK, !m_data.disable_d2d);
EnableDlgCtrl(IDC_WIN11_SETTINGS_BUTTON, theApp.m_is_windows11_taskbar);
}


Expand All @@ -128,8 +128,6 @@ void CTaskBarSettingsDlg::SetControlMouseWheelEnable(bool enable)
m_font_size_edit.SetMouseWheelEnable(enable);
m_memory_display_combo.SetMouseWheelEnable(enable);
m_item_space_edit.SetMouseWheelEnable(enable);
m_window_offset_top_edit.SetMouseWheelEnable(enable);
m_window_offset_left_edit.SetMouseWheelEnable(enable);
m_vertical_margin_edit.SetMouseWheelEnable(enable);
m_net_speed_figure_max_val_edit.SetMouseWheelEnable(enable);
m_net_speed_figure_max_val_unit_combo.SetMouseWheelEnable(enable);
Expand All @@ -152,11 +150,9 @@ void CTaskBarSettingsDlg::DoDataExchange(CDataExchange* pDX)
DDX_Control(pDX, IDC_AUTO_SET_BACK_COLOR_CHECK, m_auto_set_back_color_chk);
DDX_Control(pDX, IDC_MEMORY_DISPLAY_COMBO, m_memory_display_combo);
DDX_Control(pDX, IDC_ITEM_SPACE_EDIT, m_item_space_edit);
DDX_Control(pDX, IDC_WINDOW_OFFSET_TOP_EDIT, m_window_offset_top_edit);
DDX_Control(pDX, IDC_VERTICAL_MARGIN_EDIT, m_vertical_margin_edit);
DDX_Control(pDX, IDC_NET_SPEED_FIGURE_MAX_VALUE_EDIT, m_net_speed_figure_max_val_edit);
DDX_Control(pDX, IDC_NET_SPEED_FIGURE_MAX_VALUE_UNIT_COMBO, m_net_speed_figure_max_val_unit_combo);
DDX_Control(pDX, IDC_WINDOW_OFFSET_LEFT_EDIT, m_window_offset_left_edit);
}


Expand Down Expand Up @@ -190,18 +186,16 @@ BEGIN_MESSAGE_MAP(CTaskBarSettingsDlg, CTabDlg)
ON_CBN_SELCHANGE(IDC_MEMORY_DISPLAY_COMBO, &CTaskBarSettingsDlg::OnCbnSelchangeMemoryDisplayCombo)
ON_BN_CLICKED(IDC_SHOW_DASHED_BOX, &CTaskBarSettingsDlg::OnBnClickedShowDashedBox)
ON_BN_CLICKED(IDC_SET_ORDER_BUTTON, &CTaskBarSettingsDlg::OnBnClickedSetOrderButton)
ON_BN_CLICKED(IDC_TASKBAR_WND_SNAP_CHECK, &CTaskBarSettingsDlg::OnBnClickedTaskbarWndSnapCheck)
ON_EN_CHANGE(IDC_ITEM_SPACE_EDIT, &CTaskBarSettingsDlg::OnEnChangeItemSpaceEdit)
ON_EN_CHANGE(IDC_WINDOW_OFFSET_TOP_EDIT, &CTaskBarSettingsDlg::OnEnChangeWindowOffsetTopEdit)
ON_EN_CHANGE(IDC_VERTICAL_MARGIN_EDIT, &CTaskBarSettingsDlg::OnEnChangeVerticalMarginEdit)
ON_BN_CLICKED(IDC_SHOW_NET_SPEED_FIGURE_CHECK, &CTaskBarSettingsDlg::OnBnClickedShowNetSpeedFigureCheck)
ON_CBN_SELCHANGE(IDC_NET_SPEED_FIGURE_MAX_VALUE_UNIT_COMBO, &CTaskBarSettingsDlg::OnCbnSelchangeNetSpeedFigureMaxValueUnitCombo)
ON_EN_CHANGE(IDC_NET_SPEED_FIGURE_MAX_VALUE_EDIT, &CTaskBarSettingsDlg::OnEnChangeNetSpeedFigureMaxValueEdit)
ON_BN_CLICKED(IDC_GDI_RADIO, &CTaskBarSettingsDlg::OnBnClickedGdiRadio)
ON_BN_CLICKED(IDC_D2D_RADIO, &CTaskBarSettingsDlg::OnBnClickedD2dRadio)
ON_BN_CLICKED(IDC_ENABLE_COLOR_EMOJI_CHECK, &CTaskBarSettingsDlg::OnBnClickedEnableColorEmojiCheck)
ON_EN_CHANGE(IDC_WINDOW_OFFSET_LEFT_EDIT, &CTaskBarSettingsDlg::OnEnChangeWindowOffsetLeftEdit)
ON_CBN_SELCHANGE(IDC_DIGIT_NUMBER_COMBO, &CTaskBarSettingsDlg::OnCbnSelchangeDigitNumberCombo)
ON_BN_CLICKED(IDC_WIN11_SETTINGS_BUTTON, &CTaskBarSettingsDlg::OnBnClickedWin11SettingsButton)
END_MESSAGE_MAP()


Expand Down Expand Up @@ -238,9 +232,6 @@ BOOL CTaskBarSettingsDlg::OnInitDialog()
((CButton*)GetDlgItem(IDC_SEPARATE_VALUE_UNIT_CHECK))->SetCheck(m_data.separate_value_unit_with_space);
((CButton*)GetDlgItem(IDC_SHOW_TOOL_TIP_CHK))->SetCheck(m_data.show_tool_tip);

EnableDlgCtrl(IDC_TASKBAR_WND_SNAP_CHECK, theApp.m_win_version.IsWindows11OrLater());
CheckDlgButton(IDC_TASKBAR_WND_SNAP_CHECK, m_data.tbar_wnd_snap);

m_text_color_static.SetLinkCursor();
m_back_color_static.SetLinkCursor();
//m_trans_color_static.SetLinkCursor();
Expand Down Expand Up @@ -317,12 +308,6 @@ BOOL CTaskBarSettingsDlg::OnInitDialog()
m_item_space_edit.SetRange(0, 32);
m_item_space_edit.SetValue(m_data.item_space);
CTaskBarDlg* taskbar_dlg{ CTrafficMonitorDlg::Instance()->GetTaskbarWindow() };
m_window_offset_top_edit.SetRange(-5, 20);
m_window_offset_top_edit.SetValue(m_data.window_offset_top);
m_window_offset_top_edit.EnableWindow(theApp.m_is_windows11_taskbar);
m_window_offset_left_edit.SetRange(-800, 800);
m_window_offset_left_edit.SetValue(m_data.window_offset_left);
m_window_offset_left_edit.EnableWindow(theApp.m_is_windows11_taskbar);
m_vertical_margin_edit.SetRange(-10, 10);
m_vertical_margin_edit.SetValue(m_data.vertical_margin);
if (taskbar_dlg != nullptr)
Expand Down Expand Up @@ -770,13 +755,6 @@ void CTaskBarSettingsDlg::OnBnClickedSetOrderButton()
}


void CTaskBarSettingsDlg::OnBnClickedTaskbarWndSnapCheck()
{
// TODO: 在此添加控件通知处理程序代码
m_data.tbar_wnd_snap = (IsDlgButtonChecked(IDC_TASKBAR_WND_SNAP_CHECK) != 0);
}


void CTaskBarSettingsDlg::OnEnChangeItemSpaceEdit()
{
// TODO: 如果该控件是 RICHEDIT 控件,它将不
Expand All @@ -789,12 +767,6 @@ void CTaskBarSettingsDlg::OnEnChangeItemSpaceEdit()
m_data.ValidItemSpace();
}

void CTaskBarSettingsDlg::OnEnChangeWindowOffsetTopEdit()
{
m_data.window_offset_top = m_window_offset_top_edit.GetValue();
m_data.ValidWindowOffsetTop();
}

void CTaskBarSettingsDlg::OnEnChangeVerticalMarginEdit()
{
m_data.vertical_margin = m_vertical_margin_edit.GetValue();
Expand Down Expand Up @@ -863,16 +835,15 @@ void CTaskBarSettingsDlg::OnBnClickedEnableColorEmojiCheck()
}


void CTaskBarSettingsDlg::OnEnChangeWindowOffsetLeftEdit()
void CTaskBarSettingsDlg::OnCbnSelchangeDigitNumberCombo()
{
m_data.window_offset_left = m_window_offset_left_edit.GetValue();
m_data.ValidWindowOffsetLeft();

//获取数据位数的设置
m_data.digits_number = m_digit_number_combo.GetCurSel() + 3;
}


void CTaskBarSettingsDlg::OnCbnSelchangeDigitNumberCombo()
void CTaskBarSettingsDlg::OnBnClickedWin11SettingsButton()
{
//获取数据位数的设置
m_data.digits_number = m_digit_number_combo.GetCurSel() + 3;
CWin11TaskbarSettingDlg dlg(m_data);
dlg.DoModal();
}
6 changes: 1 addition & 5 deletions TrafficMonitor/TaskBarSettingsDlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ class CTaskBarSettingsDlg : public CTabDlg
CButton m_auto_set_back_color_chk;
CComboBox2 m_memory_display_combo;
CSpinEdit m_item_space_edit;
CSpinEdit m_window_offset_top_edit;
CSpinEdit m_window_offset_left_edit;
CSpinEdit m_vertical_margin_edit;
CSpinEdit m_net_speed_figure_max_val_edit;
CComboBox2 m_net_speed_figure_max_val_unit_combo;
Expand Down Expand Up @@ -109,9 +107,7 @@ class CTaskBarSettingsDlg : public CTabDlg
afx_msg void OnCbnSelchangeMemoryDisplayCombo();
afx_msg void OnBnClickedShowDashedBox();
afx_msg void OnBnClickedSetOrderButton();
afx_msg void OnBnClickedTaskbarWndSnapCheck();
afx_msg void OnEnChangeItemSpaceEdit();
afx_msg void OnEnChangeWindowOffsetTopEdit();
afx_msg void OnEnChangeVerticalMarginEdit();
virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam);
afx_msg void OnBnClickedShowNetSpeedFigureCheck();
Expand All @@ -120,6 +116,6 @@ class CTaskBarSettingsDlg : public CTabDlg
afx_msg void OnBnClickedGdiRadio();
afx_msg void OnBnClickedD2dRadio();
afx_msg void OnBnClickedEnableColorEmojiCheck();
afx_msg void OnEnChangeWindowOffsetLeftEdit();
afx_msg void OnCbnSelchangeDigitNumberCombo();
afx_msg void OnBnClickedWin11SettingsButton();
};
8 changes: 4 additions & 4 deletions TrafficMonitor/TrafficMonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ void CTrafficMonitorApp::LoadConfig()
m_taskbar_data.ValidItemSpace();
m_taskbar_data.ValidWindowOffsetTop();
m_taskbar_data.ValidWindowOffsetLeft();
m_taskbar_data.avoid_overlap_with_widgets = ini.GetBool(_T("task_bar"), _T("avoid_overlap_with_widgets"), false);
m_taskbar_data.taskbar_left_space_win11 = ini.GetInt(L"task_bar", L"taskbar_left_space_win11", 160);

if (m_win_version.IsWindows10OrLater()) //只有Win10才支持自动适应系统深色/浅色主题
m_taskbar_data.auto_adapt_light_theme = ini.GetBool(L"task_bar", L"auto_adapt_light_theme", false);
Expand Down Expand Up @@ -314,8 +316,6 @@ void CTrafficMonitorApp::LoadConfig()
m_last_light_mode = ini.GetBool(L"other", L"last_light_mode", CWindowsSettingHelper::IsWindows10LightTheme());
m_show_mouse_panetrate_tip = ini.GetBool(L"other", L"show_mouse_panetrate_tip", true);
m_show_dot_net_notinstalled_tip = ini.GetBool(L"other", L"show_dot_net_notinstalled_tip", true);

m_cfg_data.taskbar_left_space_win11 = ini.GetInt(L"task_bar", L"taskbar_left_space_win11", 160);
}

void CTrafficMonitorApp::SaveConfig()
Expand Down Expand Up @@ -455,6 +455,8 @@ void CTrafficMonitorApp::SaveConfig()
ini.WriteInt(L"task_bar", L"vertical_margin", m_taskbar_data.vertical_margin);
ini.WriteInt(L"task_bar", L"window_offset_top", m_taskbar_data.window_offset_top);
ini.WriteInt(L"task_bar", L"window_offset_left", m_taskbar_data.window_offset_left);
ini.WriteBool(L"task_bar", L"avoid_overlap_with_widgets", m_taskbar_data.avoid_overlap_with_widgets);
ini.WriteInt(L"task_bar", L"taskbar_left_space_win11", m_taskbar_data.taskbar_left_space_win11);

ini.WriteBool(L"task_bar", L"auto_adapt_light_theme", m_taskbar_data.auto_adapt_light_theme);
ini.WriteInt(L"task_bar", L"dark_default_style", m_taskbar_data.dark_default_style);
Expand Down Expand Up @@ -489,8 +491,6 @@ void CTrafficMonitorApp::SaveConfig()

ini.WriteString(L"config", L"plugin_disabled", m_cfg_data.plugin_disabled.ToString());

ini.WriteInt(L"task_bar", L"taskbar_left_space_win11", m_cfg_data.taskbar_left_space_win11);

ini.WriteString(L"app", L"version", VERSION);

//检查是否保存成功
Expand Down
Binary file modified TrafficMonitor/TrafficMonitor.rc
Binary file not shown.
2 changes: 2 additions & 0 deletions TrafficMonitor/TrafficMonitor.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,7 @@
<ClInclude Include="TrafficMonitorDlg.h" />
<ClInclude Include="UpdateHelper.h" />
<ClInclude Include="WIC.h" />
<ClInclude Include="Win11TaskbarSettingDlg.h" />
<ClInclude Include="WindowsSettingHelper.h" />
<ClInclude Include="WindowsWebExperienceDetector.h" />
<ClInclude Include="WinVersionHelper.h" />
Expand Down Expand Up @@ -960,6 +961,7 @@
<ClCompile Include="TrafficMonitorDlg.cpp" />
<ClCompile Include="UpdateHelper.cpp" />
<ClCompile Include="WIC.cpp" />
<ClCompile Include="Win11TaskbarSettingDlg.cpp" />
<ClCompile Include="WindowsSettingHelper.cpp" />
<ClCompile Include="WindowsWebExperienceDetector.cpp" />
<ClCompile Include="WinVersionHelper.cpp" />
Expand Down
9 changes: 9 additions & 0 deletions TrafficMonitor/TrafficMonitor.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@
<Filter Include="资源文件\bitmaps">
<UniqueIdentifier>{322d1b74-5d71-43bd-ae50-b33f24b1b31c}</UniqueIdentifier>
</Filter>
<Filter Include="源文件和头文件\对话框类\选项设置对话框\Win11TaskbarSettingDlg">
<UniqueIdentifier>{d048fa7a-2509-4713-9df3-c537c4b35018}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<Text Include="ReadMe.txt" />
Expand Down Expand Up @@ -505,6 +508,9 @@
<ClInclude Include="FileDialogEx.h">
<Filter>源文件和头文件\头文件</Filter>
</ClInclude>
<ClInclude Include="Win11TaskbarSettingDlg.h">
<Filter>源文件和头文件\对话框类\选项设置对话框\Win11TaskbarSettingDlg</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="StaticEx.cpp">
Expand Down Expand Up @@ -744,6 +750,9 @@
<ClCompile Include="FileDialogEx.cpp">
<Filter>源文件和头文件</Filter>
</ClCompile>
<ClCompile Include="Win11TaskbarSettingDlg.cpp">
<Filter>源文件和头文件\对话框类\选项设置对话框\Win11TaskbarSettingDlg</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="TrafficMonitor.rc">
Expand Down
Loading

0 comments on commit 5f18357

Please sign in to comment.