Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/ManagedShell.AppBar/AppBarWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ public AppBarWindow(AppBarManager appBarManager, ExplorerHelper explorerHelper,
PropertyChanged += AppBarWindow_PropertyChanged;

ResizeMode = ResizeMode.NoResize;
if (EnvironmentHelper.IsWindows11OrBetter)
{
// With Windows 11, we cannot use the normal way to hide from taskbar (setting as a tool window) because that breaks receiving WM_DPICHANGED.
ShowInTaskbar = false;
}
Title = "";
Topmost = true;
UseLayoutRounding = true;
Expand Down
29 changes: 28 additions & 1 deletion src/ManagedShell.Common/Helpers/WindowHelper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Runtime.InteropServices;
using System.Text;
using static ManagedShell.Interop.NativeMethods;

namespace ManagedShell.Common.Helpers
Expand Down Expand Up @@ -102,7 +103,33 @@ public static IntPtr GetLowestDesktopChildHwnd()

public static void HideWindowFromTasks(IntPtr hWnd)
{
SetWindowLong(hWnd, GWL_EXSTYLE, (GetWindowLong(hWnd, GWL_EXSTYLE) & ~(int)ExtendedWindowStyles.WS_EX_APPWINDOW) | (int)ExtendedWindowStyles.WS_EX_TOOLWINDOW);
int style = GetWindowLong(hWnd, GWL_EXSTYLE) & ~(int)ExtendedWindowStyles.WS_EX_APPWINDOW;
if (EnvironmentHelper.IsWindows11OrBetter)
{
// If the window has a Hidden Window owner, set the owner as a tool window instead so that we still receive WM_DPICHANGED on Windows 11.
// Hidden Window is the owner when ShowInTaskbar=false. Unfortunately, the window will not be hidden from Task Manager.
// https://github.com/dotnet/wpf/issues/10422
IntPtr hwndOwner = GetWindow(hWnd, GetWindow_Cmd.GW_OWNER);
if (hwndOwner == IntPtr.Zero)
{
style |= (int)ExtendedWindowStyles.WS_EX_TOOLWINDOW;
}
else
{
int TITLE_LENGTH = 1024;
StringBuilder titleBuilder = new StringBuilder(TITLE_LENGTH);
GetWindowText(hwndOwner, titleBuilder, TITLE_LENGTH + 1);
if (titleBuilder.ToString() == "Hidden Window")
{
SetWindowLong(hwndOwner, GWL_EXSTYLE, GetWindowLong(hwndOwner, GWL_EXSTYLE) | (int)ExtendedWindowStyles.WS_EX_TOOLWINDOW);
}
}
}
else
{
style |= (int)ExtendedWindowStyles.WS_EX_TOOLWINDOW;
}
SetWindowLong(hWnd, GWL_EXSTYLE, style);

ExcludeWindowFromPeek(hWnd);
}
Expand Down
Loading