diff --git a/src/app/dev/platforms/desktop/DevToys.Windows/Controls/OverlayWindow.xaml.cs b/src/app/dev/platforms/desktop/DevToys.Windows/Controls/OverlayWindow.xaml.cs index 3d87456134..e9b3a297fd 100644 --- a/src/app/dev/platforms/desktop/DevToys.Windows/Controls/OverlayWindow.xaml.cs +++ b/src/app/dev/platforms/desktop/DevToys.Windows/Controls/OverlayWindow.xaml.cs @@ -1,5 +1,7 @@ using System.Windows; using System.Windows.Interop; +using DevToys.Windows.Native; +using Windows.Win32.Foundation; namespace DevToys.Windows.Controls; @@ -18,6 +20,9 @@ protected override void OnSourceInitialized(EventArgs e) var hwndSource = HwndSource.FromHwnd(windowHandle); hwndSource.AddHook(new HwndSourceHook(WndProc)); + // Hide window from Alt+Tab. + NativeMethods.HideFromAltTab(new HWND(windowHandle)); + base.OnSourceInitialized(e); } diff --git a/src/app/dev/platforms/desktop/DevToys.Windows/Native/HwndSourceMessages.cs b/src/app/dev/platforms/desktop/DevToys.Windows/Native/HwndSourceMessages.cs index 22e12ce9d7..0817b47a81 100644 --- a/src/app/dev/platforms/desktop/DevToys.Windows/Native/HwndSourceMessages.cs +++ b/src/app/dev/platforms/desktop/DevToys.Windows/Native/HwndSourceMessages.cs @@ -3,4 +3,5 @@ internal static class HwndSourceMessages { internal const int WS_CHILD = 0x40000000; + internal const int WS_EX_TOOLWINDOW = 0x00000080; } diff --git a/src/app/dev/platforms/desktop/DevToys.Windows/Native/NativeMethods.cs b/src/app/dev/platforms/desktop/DevToys.Windows/Native/NativeMethods.cs index 2aeed12dcd..e18ce3b35d 100644 --- a/src/app/dev/platforms/desktop/DevToys.Windows/Native/NativeMethods.cs +++ b/src/app/dev/platforms/desktop/DevToys.Windows/Native/NativeMethods.cs @@ -9,56 +9,52 @@ namespace DevToys.Windows.Native; internal static partial class NativeMethods { +#pragma warning disable CA1416 // Validate platform compatibility internal static unsafe HRESULT SetWindowAttribute(HWND windowHandle, DWMWINDOWATTRIBUTE attribute, ref int parameter) { -#pragma warning disable CA1416 // Validate platform compatibility fixed (void* value = ¶meter) { return PInvoke.DwmSetWindowAttribute(windowHandle, attribute, value, (uint)Marshal.SizeOf()); } -#pragma warning restore CA1416 // Validate platform compatibility } internal static int ExtendFrame(HWND windowHandle, MARGINS margins) { -#pragma warning disable CA1416 // Validate platform compatibility return PInvoke.DwmExtendFrameIntoClientArea(windowHandle, in margins); -#pragma warning restore CA1416 // Validate platform compatibility } internal static void HideAllWindowButton(HWND windowHandle) { -#pragma warning disable CA1416 // Validate platform compatibility _ = PInvoke.SetWindowLong(windowHandle, WINDOW_LONG_PTR_INDEX.GWL_STYLE, PInvoke.GetWindowLong(windowHandle, WINDOW_LONG_PTR_INDEX.GWL_STYLE) & ~HwndButtons.WS_SYSMENU); -#pragma warning restore CA1416 // Validate platform compatibility } internal static void SetWindowAsChildOf(HWND windowHandleChild, HWND windowHandleParent) { -#pragma warning disable CA1416 // Validate platform compatibility PInvoke.SetWindowLong(windowHandleChild, WINDOW_LONG_PTR_INDEX.GWL_STYLE, HwndSourceMessages.WS_CHILD); PInvoke.SetParent(windowHandleChild, windowHandleParent); -#pragma warning restore CA1416 // Validate platform compatibility } internal static void DisableMinimizeAndMaximizeCapabilities(HWND windowHandle) { -#pragma warning disable CA1416 // Validate platform compatibility HMENU systemMenuHandle = PInvoke.GetSystemMenu(windowHandle, false); PInvoke.EnableMenuItem(systemMenuHandle, (uint)PInvoke.SC_MAXIMIZE, MENU_ITEM_FLAGS.MF_BYCOMMAND | MENU_ITEM_FLAGS.MF_GRAYED); PInvoke.EnableMenuItem(systemMenuHandle, (uint)PInvoke.SC_MINIMIZE, MENU_ITEM_FLAGS.MF_BYCOMMAND | MENU_ITEM_FLAGS.MF_GRAYED); -#pragma warning restore CA1416 // Validate platform compatibility } internal static void EnableMinimizeAndMaximizeCapabilities(HWND windowHandle) { -#pragma warning disable CA1416 // Validate platform compatibility HMENU systemMenuHandle = PInvoke.GetSystemMenu(windowHandle, false); PInvoke.EnableMenuItem(systemMenuHandle, (uint)PInvoke.SC_MAXIMIZE, MENU_ITEM_FLAGS.MF_BYCOMMAND | MENU_ITEM_FLAGS.MF_ENABLED); PInvoke.EnableMenuItem(systemMenuHandle, (uint)PInvoke.SC_MINIMIZE, MENU_ITEM_FLAGS.MF_BYCOMMAND | MENU_ITEM_FLAGS.MF_ENABLED); -#pragma warning restore CA1416 // Validate platform compatibility } + internal static void HideFromAltTab(HWND windowHandle) + { + int currentStyle = PInvoke.GetWindowLong(windowHandle, WINDOW_LONG_PTR_INDEX.GWL_EXSTYLE); + PInvoke.SetWindowLong(windowHandle, WINDOW_LONG_PTR_INDEX.GWL_EXSTYLE, currentStyle | HwndSourceMessages.WS_EX_TOOLWINDOW); + } + +#pragma warning restore CA1416 // Validate platform compatibility /// /// Sets various information regarding DWM window attributes ///