AvaloniaUI / Avalonia

Develop Desktop, Embedded, Mobile and WebAssembly apps with C# and XAML. The most popular .NET UI client technology
https://avaloniaui.net
MIT License
25.73k stars 2.22k forks source link

Hide a window on alt-tab menu when ShowInTaskBar=False #16871

Open Aqueuse opened 2 months ago

Aqueuse commented 2 months ago

Is your feature request related to a problem? Please describe.

Hello,

I'm working on a C# version of Neko (https://fr.wikipedia.org/wiki/Neko_(logiciel)), a very small application and I need that my window don't interfere with the user experience, so not in the task bar nor in the alt-tab menu of Windows.

We have managed to find a solution with WPF and Avalonia 11.0.2 : the application is hidden in the task bar and on the alt-tab menu.

public partial class MainWindow : Window {
    private Image? petImage;

    private const int GWL_EXSTYLE = -20;
    private const uint WS_EX_TOOLWINDOW = 0x00000080;

    public MainWindow() {
        Loaded += SearchImage;

        InitializeComponent();

        ShowInTaskbar = false;
        WindowStartupLocation = WindowStartupLocation.Manual;
        var visualRoot = this.GetVisualRoot() as TopLevel;
        if (visualRoot != null && visualRoot.TryGetPlatformHandle() is { } platformHandle) {
            var hwnd = platformHandle.Handle;
            NativeMethods.SetWindowLong(hwnd, GWL_EXSTYLE,
                (uint)NativeMethods.GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_TOOLWINDOW);
        }
    }
}

But it's not working in Avalonia 11.2 : in the version, it's only hidden in the task bar.

Describe the solution you'd like

I would like that on Windows, ShowInTaskBar=False hide also the application in the alt-tab menu.

Describe alternatives you've considered

No response

Additional context

No response

stevemonaco commented 2 months ago

There probably should be an analysis of how portable windowing features like ShowInTaskBar is for v12. Maybe moved to Win32Properties with a separate, new attached property for tool windows to hide them from the alt+tab program switcher.