From 1e59b35ed866658cab47fab181b16abca3fa9bb0 Mon Sep 17 00:00:00 2001 From: zhongyang219 Date: Wed, 22 Jan 2025 15:14:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=BD=93=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E6=A0=8F=E4=B8=8A=E6=B2=A1=E6=9C=89=E4=BB=BB=E4=BD=95=E5=9B=BE?= =?UTF-8?q?=E6=A0=87=E6=97=B6=E4=BB=BB=E5=8A=A1=E6=A0=8F=E7=AA=97=E5=8F=A3?= =?UTF-8?q?=E7=9A=84=E4=BD=8D=E7=BD=AE=E4=B8=8D=E6=AD=A3=E7=A1=AE=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20#1913?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TrafficMonitor/TaskBarDlg.cpp | 35 ++++++++++++++++++++++------ TrafficMonitor/TaskBarDlg.h | 3 +++ TrafficMonitor/TrafficMonitorDlg.cpp | 6 +++++ 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/TrafficMonitor/TaskBarDlg.cpp b/TrafficMonitor/TaskBarDlg.cpp index b3c3e35d..776facf9 100644 --- a/TrafficMonitor/TaskBarDlg.cpp +++ b/TrafficMonitor/TaskBarDlg.cpp @@ -693,11 +693,10 @@ bool CTaskBarDlg::AdjustWindowPos() //靠近“开始”按钮 if (theApp.m_taskbar_data.tbar_wnd_snap) { - HWND m_hStart = ::FindWindowEx(m_hTaskbar, nullptr, L"Start", NULL); - CRect m_rcStart; - ::GetWindowRect(m_hStart, m_rcStart); + CRect rcStart; + ::GetWindowRect(m_hStart, rcStart); - m_rect.MoveToX(m_rcStart.left - m_rect.Width() - 2); + m_rect.MoveToX(rcStart.left - m_rect.Width() - 2); } //靠近最左侧 else @@ -719,9 +718,21 @@ bool CTaskBarDlg::AdjustWindowPos() m_rect.MoveToX(m_left_space); } } - //注:这里加上(m_rcTaskbar.Height() - m_rcBar.Height())用于修正Windows11 build 22621版本后触屏设备任务栏窗口位置不正确的问题。 - //在这种情况下m_rcTaskbar的高度要大于m_rcBar的高度,正常情况下,它们的高度相同 - m_rect.MoveToY((m_rcBar.Height() - m_rect.Height()) / 2 + (m_rcTaskbar.Height() - m_rcBar.Height()) + DPI(theApp.m_taskbar_data.window_offset_top)); + + //设置任务栏窗口的垂直位置 + if (theApp.m_is_windows11_taskbar) + { + CRect rcStart; + ::GetWindowRect(m_hStart, rcStart); + //注:这里加上(m_rcTaskbar.Height() - rcStart.Height())用于修正Windows11 build 22621版本后触屏设备任务栏窗口位置不正确的问题。 + //在这种情况下m_rcTaskbar的高度要大于m_rcBar的高度,正常情况下,它们的高度相同 + //但是当任务栏上没有任何图标时,m_rcBar的高度会变为0,因此使用rcStart代替 + m_rect.MoveToY((rcStart.Height() - m_rect.Height()) / 2 + (m_rcTaskbar.Height() - rcStart.Height()) + DPI(theApp.m_taskbar_data.window_offset_top)); + } + else + { + m_rect.MoveToY((m_rcBar.Height() - m_rect.Height()) / 2 + DPI(theApp.m_taskbar_data.window_offset_top)); + } if (theApp.m_taskbar_data.horizontal_arrange && theApp.m_win_version.IsWindows7()) m_rect.MoveToY(m_rect.top + DPI(1)); MoveWindow(m_rect); @@ -1248,6 +1259,15 @@ bool CTaskBarDlg::IsTaskbarCloseToIconEnable(bool taskbar_wnd_on_left) ); } +std::wstring CTaskBarDlg::GetTaskbarDebugString() const +{ + std::wstring str = std::format(L"m_rcTaskbar: 左上坐标({},{}) 左下坐标({},{}) 大小({}x{})" + "\r\nm_rcBar: 左上坐标({},{}) 左下坐标({},{}) 大小({}x{})", + m_rcTaskbar.left, m_rcTaskbar.top, m_rcTaskbar.right, m_rcTaskbar.bottom, m_rcTaskbar.Width(), m_rcTaskbar.Height(), + m_rcBar.left, m_rcBar.top, m_rcBar.right, m_rcBar.bottom, m_rcBar.Width(), m_rcBar.Height()); + return str; +} + BOOL CTaskBarDlg::OnInitDialog() { CDialogEx::OnInitDialog(); @@ -1268,6 +1288,7 @@ BOOL CTaskBarDlg::OnInitDialog() m_hMin = ::FindWindowEx(m_hBar, 0, L"MSTaskSwWClass", NULL); //寻找最小化窗口的句柄 m_hNotify = ::FindWindowEx(m_hTaskbar, 0, L"TrayNotifyWnd", NULL); + m_hStart = ::FindWindowEx(m_hTaskbar, nullptr, L"Start", NULL); //设置窗口透明色 ApplyWindowTransparentColor(); diff --git a/TrafficMonitor/TaskBarDlg.h b/TrafficMonitor/TaskBarDlg.h index ee31d95a..f679b72e 100644 --- a/TrafficMonitor/TaskBarDlg.h +++ b/TrafficMonitor/TaskBarDlg.h @@ -83,6 +83,7 @@ class CTaskBarDlg : public CDialogEx HWND m_hBar; //任务栏窗口二级容器的句柄 HWND m_hMin; //最小化窗口的句柄 HWND m_hNotify; //任务栏通知区域的句柄 + HWND m_hStart; //开始按钮的句柄 CRect m_rcTaskbar; //任务栏的矩形区域 CRect m_rcNotify; //任务栏通知区域的矩形区域 @@ -209,6 +210,8 @@ class CTaskBarDlg : public CDialogEx //taskbar_wnd_on_left: 任务栏窗口是否在任务栏左侧 static bool IsTaskbarCloseToIconEnable(bool taskbar_wnd_on_left); + std::wstring GetTaskbarDebugString() const; + DECLARE_MESSAGE_MAP() public: diff --git a/TrafficMonitor/TrafficMonitorDlg.cpp b/TrafficMonitor/TrafficMonitorDlg.cpp index a6d86be1..5fed0c6a 100644 --- a/TrafficMonitor/TrafficMonitorDlg.cpp +++ b/TrafficMonitor/TrafficMonitorDlg.cpp @@ -208,6 +208,12 @@ CString CTrafficMonitorDlg::GetMouseTipsInfo() //添加插件项目的鼠标提示 tip_info += theApp.GetPlauginTooltipInfo().c_str(); + //if (IsTaskbarWndValid()) + //{ + // tip_info += L"\r\n"; + // tip_info += m_tBarDlg->GetTaskbarDebugString().c_str(); + //} + return tip_info; }