From 67f6fda900f36f91a2580f821dfe9e85e6802331 Mon Sep 17 00:00:00 2001 From: qhy040404 Date: Sun, 26 May 2024 21:53:22 +0800 Subject: [PATCH 1/4] another impl of hint when icon promoted for win10 --- .../Core/Windowing/XamlWindowController.cs | 28 ++++++++++++++++-- src/Snap.Hutao/Snap.Hutao/Win32/User32.cs | 29 +++++++++++++++++++ 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/XamlWindowController.cs b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/XamlWindowController.cs index 2ebd955f..512b0c69 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/XamlWindowController.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/XamlWindowController.cs @@ -104,9 +104,7 @@ internal sealed class XamlWindowController args.Handled = true; window.Hide(); - RECT iconRect = serviceProvider.GetRequiredService().GetRect(); - RECT primaryRect = StructMarshal.RECT(DisplayArea.Primary.OuterBounds); - if (!IntersectRect(out _, in primaryRect, in iconRect)) + if (!IsNotifyIconVisible()) { new ToastContentBuilder() .AddText(SH.CoreWindowingNotifyIconPromotedHint) @@ -133,6 +131,30 @@ internal sealed class XamlWindowController } } + private unsafe bool IsNotifyIconVisible() + { + RECT iconRect = serviceProvider.GetRequiredService().GetRect(); + + if (UniversalApiContract.IsPresent(WindowsVersion.Windows11)) + { + RECT primaryRect = StructMarshal.RECT(DisplayArea.Primary.OuterBounds); + return IntersectRect(out _, in primaryRect, in iconRect); + } + else + { + HWND shellTrayWnd = FindWindowExW(default, default, "Shell_TrayWnd", default); + HWND trayNotifyWnd = FindWindowExW(shellTrayWnd, default, "TrayNotifyWnd", default); + HWND button = FindWindowExW(trayNotifyWnd, default, "Button", default); + + if (GetWindowRect(button, out RECT buttonRect)) + { + return !EqualRect(in buttonRect, in iconRect); + } + + return false; + } + } + #region SystemBackdrop & ElementTheme private void OnOptionsPropertyChanged(object? sender, PropertyChangedEventArgs e) diff --git a/src/Snap.Hutao/Snap.Hutao/Win32/User32.cs b/src/Snap.Hutao/Snap.Hutao/Win32/User32.cs index 795ab2e1..c6ed2ea7 100644 --- a/src/Snap.Hutao/Snap.Hutao/Win32/User32.cs +++ b/src/Snap.Hutao/Snap.Hutao/Win32/User32.cs @@ -55,6 +55,22 @@ internal static class User32 [SupportedOSPlatform("windows5.0")] public static extern BOOL DestroyWindow(HWND hWnd); + [DllImport("USER32.dll", CallingConvention = CallingConvention.Winapi, ExactSpelling = true)] + [SupportedOSPlatform("windows5.0")] + public static unsafe extern BOOL EqualRect(RECT* lprc1, RECT* lprc2); + + [DebuggerStepThrough] + public static unsafe BOOL EqualRect(in RECT rc1, in RECT rc2) + { + fixed (RECT* lprc1 = &rc1) + { + fixed (RECT* lprc2 = &rc2) + { + return EqualRect(lprc1, lprc2); + } + } + } + [DllImport("USER32.dll", CallingConvention = CallingConvention.Winapi, ExactSpelling = true)] [SupportedOSPlatform("windows5.0")] public static extern HWND FindWindowExW([AllowNull] HWND hWndParent, [AllowNull] HWND hWndChildAfter, [AllowNull] PCWSTR lpszClass, [AllowNull] PCWSTR lpszWindow); @@ -112,6 +128,19 @@ internal static class User32 } } + [DllImport("USER32.dll", CallingConvention = CallingConvention.Winapi, ExactSpelling = true)] + [SupportedOSPlatform("windows5.0")] + public static unsafe extern BOOL GetWindowRect(HWND hWnd, RECT* lpRect); + + [DebuggerStepThrough] + public static unsafe BOOL GetWindowRect(HWND hWnd, out RECT rect) + { + fixed (RECT* lpRect = &rect) + { + return GetWindowRect(hWnd, lpRect); + } + } + [DllImport("USER32.dll", CallingConvention = CallingConvention.Winapi, ExactSpelling = true)] [SupportedOSPlatform("windows5.0")] public static unsafe extern uint GetWindowThreadProcessId(HWND hWnd, [MaybeNull] uint* lpdwProcessId); From cd91af8ae96c93f8abb742332fbacd456f2c2eca Mon Sep 17 00:00:00 2001 From: qhy040404 Date: Mon, 27 May 2024 09:29:58 +0800 Subject: [PATCH 2/4] use ref readonly --- src/Snap.Hutao/Snap.Hutao/Win32/User32.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Snap.Hutao/Snap.Hutao/Win32/User32.cs b/src/Snap.Hutao/Snap.Hutao/Win32/User32.cs index c6ed2ea7..e09b933a 100644 --- a/src/Snap.Hutao/Snap.Hutao/Win32/User32.cs +++ b/src/Snap.Hutao/Snap.Hutao/Win32/User32.cs @@ -60,7 +60,7 @@ internal static class User32 public static unsafe extern BOOL EqualRect(RECT* lprc1, RECT* lprc2); [DebuggerStepThrough] - public static unsafe BOOL EqualRect(in RECT rc1, in RECT rc2) + public static unsafe BOOL EqualRect(ref readonly RECT rc1, ref readonly RECT rc2) { fixed (RECT* lprc1 = &rc1) { From 7aa4696ba513d4af0c411bd4ebbe4a1a33560399 Mon Sep 17 00:00:00 2001 From: qhy040404 Date: Mon, 27 May 2024 22:11:38 +0800 Subject: [PATCH 3/4] drop else --- .../Core/Windowing/XamlWindowController.cs | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/XamlWindowController.cs b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/XamlWindowController.cs index 512b0c69..a78cf106 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/XamlWindowController.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/XamlWindowController.cs @@ -140,19 +140,17 @@ internal sealed class XamlWindowController RECT primaryRect = StructMarshal.RECT(DisplayArea.Primary.OuterBounds); return IntersectRect(out _, in primaryRect, in iconRect); } - else + + HWND shellTrayWnd = FindWindowExW(default, default, "Shell_TrayWnd", default); + HWND trayNotifyWnd = FindWindowExW(shellTrayWnd, default, "TrayNotifyWnd", default); + HWND button = FindWindowExW(trayNotifyWnd, default, "Button", default); + + if (GetWindowRect(button, out RECT buttonRect)) { - HWND shellTrayWnd = FindWindowExW(default, default, "Shell_TrayWnd", default); - HWND trayNotifyWnd = FindWindowExW(shellTrayWnd, default, "TrayNotifyWnd", default); - HWND button = FindWindowExW(trayNotifyWnd, default, "Button", default); - - if (GetWindowRect(button, out RECT buttonRect)) - { - return !EqualRect(in buttonRect, in iconRect); - } - - return false; + return !EqualRect(in buttonRect, in iconRect); } + + return false; } #region SystemBackdrop & ElementTheme From 9f8f2870aef1f933cf4e1e664beeb5ea610e0af5 Mon Sep 17 00:00:00 2001 From: Lightczx <1686188646@qq.com> Date: Tue, 28 May 2024 16:01:13 +0800 Subject: [PATCH 4/4] remove blank spaces --- .../Snap.Hutao/Core/Windowing/XamlWindowController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/XamlWindowController.cs b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/XamlWindowController.cs index a78cf106..816af2c2 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/XamlWindowController.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/XamlWindowController.cs @@ -140,7 +140,7 @@ internal sealed class XamlWindowController RECT primaryRect = StructMarshal.RECT(DisplayArea.Primary.OuterBounds); return IntersectRect(out _, in primaryRect, in iconRect); } - + HWND shellTrayWnd = FindWindowExW(default, default, "Shell_TrayWnd", default); HWND trayNotifyWnd = FindWindowExW(shellTrayWnd, default, "TrayNotifyWnd", default); HWND button = FindWindowExW(trayNotifyWnd, default, "Button", default);