Skip to content

Commit 1e59b35

Browse files
committed
修正当任务栏上没有任何图标时任务栏窗口的位置不正确的问题 #1913
1 parent 6ad9a83 commit 1e59b35

File tree

3 files changed

+37
-7
lines changed

3 files changed

+37
-7
lines changed

TrafficMonitor/TaskBarDlg.cpp

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -693,11 +693,10 @@ bool CTaskBarDlg::AdjustWindowPos()
693693
//靠近“开始”按钮
694694
if (theApp.m_taskbar_data.tbar_wnd_snap)
695695
{
696-
HWND m_hStart = ::FindWindowEx(m_hTaskbar, nullptr, L"Start", NULL);
697-
CRect m_rcStart;
698-
::GetWindowRect(m_hStart, m_rcStart);
696+
CRect rcStart;
697+
::GetWindowRect(m_hStart, rcStart);
699698

700-
m_rect.MoveToX(m_rcStart.left - m_rect.Width() - 2);
699+
m_rect.MoveToX(rcStart.left - m_rect.Width() - 2);
701700
}
702701
//靠近最左侧
703702
else
@@ -719,9 +718,21 @@ bool CTaskBarDlg::AdjustWindowPos()
719718
m_rect.MoveToX(m_left_space);
720719
}
721720
}
722-
//注:这里加上(m_rcTaskbar.Height() - m_rcBar.Height())用于修正Windows11 build 22621版本后触屏设备任务栏窗口位置不正确的问题。
723-
//在这种情况下m_rcTaskbar的高度要大于m_rcBar的高度,正常情况下,它们的高度相同
724-
m_rect.MoveToY((m_rcBar.Height() - m_rect.Height()) / 2 + (m_rcTaskbar.Height() - m_rcBar.Height()) + DPI(theApp.m_taskbar_data.window_offset_top));
721+
722+
//设置任务栏窗口的垂直位置
723+
if (theApp.m_is_windows11_taskbar)
724+
{
725+
CRect rcStart;
726+
::GetWindowRect(m_hStart, rcStart);
727+
//注:这里加上(m_rcTaskbar.Height() - rcStart.Height())用于修正Windows11 build 22621版本后触屏设备任务栏窗口位置不正确的问题。
728+
//在这种情况下m_rcTaskbar的高度要大于m_rcBar的高度,正常情况下,它们的高度相同
729+
//但是当任务栏上没有任何图标时,m_rcBar的高度会变为0,因此使用rcStart代替
730+
m_rect.MoveToY((rcStart.Height() - m_rect.Height()) / 2 + (m_rcTaskbar.Height() - rcStart.Height()) + DPI(theApp.m_taskbar_data.window_offset_top));
731+
}
732+
else
733+
{
734+
m_rect.MoveToY((m_rcBar.Height() - m_rect.Height()) / 2 + DPI(theApp.m_taskbar_data.window_offset_top));
735+
}
725736
if (theApp.m_taskbar_data.horizontal_arrange && theApp.m_win_version.IsWindows7())
726737
m_rect.MoveToY(m_rect.top + DPI(1));
727738
MoveWindow(m_rect);
@@ -1248,6 +1259,15 @@ bool CTaskBarDlg::IsTaskbarCloseToIconEnable(bool taskbar_wnd_on_left)
12481259
);
12491260
}
12501261

1262+
std::wstring CTaskBarDlg::GetTaskbarDebugString() const
1263+
{
1264+
std::wstring str = std::format(L"m_rcTaskbar: 左上坐标({},{}) 左下坐标({},{}) 大小({}x{})"
1265+
"\r\nm_rcBar: 左上坐标({},{}) 左下坐标({},{}) 大小({}x{})",
1266+
m_rcTaskbar.left, m_rcTaskbar.top, m_rcTaskbar.right, m_rcTaskbar.bottom, m_rcTaskbar.Width(), m_rcTaskbar.Height(),
1267+
m_rcBar.left, m_rcBar.top, m_rcBar.right, m_rcBar.bottom, m_rcBar.Width(), m_rcBar.Height());
1268+
return str;
1269+
}
1270+
12511271
BOOL CTaskBarDlg::OnInitDialog()
12521272
{
12531273
CDialogEx::OnInitDialog();
@@ -1268,6 +1288,7 @@ BOOL CTaskBarDlg::OnInitDialog()
12681288
m_hMin = ::FindWindowEx(m_hBar, 0, L"MSTaskSwWClass", NULL); //寻找最小化窗口的句柄
12691289

12701290
m_hNotify = ::FindWindowEx(m_hTaskbar, 0, L"TrayNotifyWnd", NULL);
1291+
m_hStart = ::FindWindowEx(m_hTaskbar, nullptr, L"Start", NULL);
12711292

12721293
//设置窗口透明色
12731294
ApplyWindowTransparentColor();

TrafficMonitor/TaskBarDlg.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ class CTaskBarDlg : public CDialogEx
8383
HWND m_hBar; //任务栏窗口二级容器的句柄
8484
HWND m_hMin; //最小化窗口的句柄
8585
HWND m_hNotify; //任务栏通知区域的句柄
86+
HWND m_hStart; //开始按钮的句柄
8687

8788
CRect m_rcTaskbar; //任务栏的矩形区域
8889
CRect m_rcNotify; //任务栏通知区域的矩形区域
@@ -209,6 +210,8 @@ class CTaskBarDlg : public CDialogEx
209210
//taskbar_wnd_on_left: 任务栏窗口是否在任务栏左侧
210211
static bool IsTaskbarCloseToIconEnable(bool taskbar_wnd_on_left);
211212

213+
std::wstring GetTaskbarDebugString() const;
214+
212215
DECLARE_MESSAGE_MAP()
213216

214217
public:

TrafficMonitor/TrafficMonitorDlg.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,12 @@ CString CTrafficMonitorDlg::GetMouseTipsInfo()
208208
//添加插件项目的鼠标提示
209209
tip_info += theApp.GetPlauginTooltipInfo().c_str();
210210

211+
//if (IsTaskbarWndValid())
212+
//{
213+
// tip_info += L"\r\n";
214+
// tip_info += m_tBarDlg->GetTaskbarDebugString().c_str();
215+
//}
216+
211217
return tip_info;
212218
}
213219

0 commit comments

Comments
 (0)