[FZ Editor] hide tool windows from alt-tab (#10011)

This commit is contained in:
Enrico Giordani 2021-03-04 13:49:29 +01:00 committed by GitHub
parent b5ca691e69
commit f7e2fa5263
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 2 deletions

View File

@ -12,4 +12,5 @@
ResizeMode="NoResize"
WindowStyle="None"
AllowsTransparency="True"
Loaded="Window_Loaded"
Background="{DynamicResource BackdropBrush}"/>

View File

@ -2,9 +2,7 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Windows;
using System.Windows.Media;
namespace FancyZonesEditor
{
@ -17,5 +15,10 @@ namespace FancyZonesEditor
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
Utils.NativeMethods.SetWindowStyleToolWindow(this);
}
}
}

View File

@ -0,0 +1,32 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Interop;
namespace FancyZonesEditor.Utils
{
internal class NativeMethods
{
[DllImport("user32.dll", SetLastError = true)]
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll")]
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
#pragma warning disable SA1310 // Field names should not contain underscore
private const int GWL_EX_STYLE = -20;
private const int WS_EX_APPWINDOW = 0x00040000;
private const int WS_EX_TOOLWINDOW = 0x00000080;
#pragma warning restore SA1310 // Field names should not contain underscore
public static void SetWindowStyleToolWindow(Window hwnd)
{
var helper = new WindowInteropHelper(hwnd).Handle;
SetWindowLong(helper, GWL_EX_STYLE, (GetWindowLong(helper, GWL_EX_STYLE) | WS_EX_TOOLWINDOW) & ~WS_EX_APPWINDOW);
}
}
}