From ac52453ae8ff8b4611b87a3083a856a92565d421 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Sat, 18 Jul 2026 23:55:04 -0500 Subject: [PATCH 1/3] Use Get/SetWindowLongPtr --- src/ManagedShell.AppBar/FullScreenHelper.cs | 4 +-- .../Helpers/WindowHelper.cs | 6 ++-- .../SupportingClasses/ShellWindow.cs | 6 ++-- .../NativeMethods.User32.cs | 28 +++++++++++++++++-- .../ApplicationWindow.cs | 4 +-- src/ManagedShell.WindowsTray/TrayService.cs | 6 ++-- 6 files changed, 39 insertions(+), 15 deletions(-) diff --git a/src/ManagedShell.AppBar/FullScreenHelper.cs b/src/ManagedShell.AppBar/FullScreenHelper.cs index fb67b6ab..5d543360 100644 --- a/src/ManagedShell.AppBar/FullScreenHelper.cs +++ b/src/ManagedShell.AppBar/FullScreenHelper.cs @@ -141,7 +141,7 @@ private void updateFullScreenWindows() else { // Still full screen but no longer active - if ((GetWindowLong(hWnd, GWL_EXSTYLE) & (int)ExtendedWindowStyles.WS_EX_TOPMOST) == (int)ExtendedWindowStyles.WS_EX_TOPMOST) + if (((int)GetWindowLongPtr(hWnd, GWL_EXSTYLE) & (int)ExtendedWindowStyles.WS_EX_TOPMOST) == (int)ExtendedWindowStyles.WS_EX_TOPMOST) { // If the new foreground window is a topmost window, don't consider this full-screen app inactive continue; @@ -265,7 +265,7 @@ private FullScreenApp getFullScreenApp(IntPtr hWnd, bool fromTasksService = fals private Rect GetEffectiveWindowRect(IntPtr hWnd) { - int style = GetWindowLong(hWnd, GWL_STYLE); + int style = (int)GetWindowLongPtr(hWnd, GWL_STYLE); Rect rect; if ((((int)WindowStyles.WS_CAPTION | (int)WindowStyles.WS_THICKFRAME) & style) == ((int)WindowStyles.WS_CAPTION | (int)WindowStyles.WS_THICKFRAME) || diff --git a/src/ManagedShell.Common/Helpers/WindowHelper.cs b/src/ManagedShell.Common/Helpers/WindowHelper.cs index df8835ed..ced7288f 100644 --- a/src/ManagedShell.Common/Helpers/WindowHelper.cs +++ b/src/ManagedShell.Common/Helpers/WindowHelper.cs @@ -103,7 +103,7 @@ public static IntPtr GetLowestDesktopChildHwnd() public static void HideWindowFromTasks(IntPtr hWnd) { - int style = GetWindowLong(hWnd, GWL_EXSTYLE) & ~(int)ExtendedWindowStyles.WS_EX_APPWINDOW; + int style = (int)GetWindowLongPtr(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. @@ -121,7 +121,7 @@ public static void HideWindowFromTasks(IntPtr hWnd) GetWindowText(hwndOwner, titleBuilder, TITLE_LENGTH + 1); if (titleBuilder.ToString() == "Hidden Window") { - SetWindowLong(hwndOwner, GWL_EXSTYLE, GetWindowLong(hwndOwner, GWL_EXSTYLE) | (int)ExtendedWindowStyles.WS_EX_TOOLWINDOW); + SetWindowLongPtr(hwndOwner, GWL_EXSTYLE, (IntPtr)((int)GetWindowLongPtr(hwndOwner, GWL_EXSTYLE) | (int)ExtendedWindowStyles.WS_EX_TOOLWINDOW)); } } } @@ -129,7 +129,7 @@ public static void HideWindowFromTasks(IntPtr hWnd) { style |= (int)ExtendedWindowStyles.WS_EX_TOOLWINDOW; } - SetWindowLong(hWnd, GWL_EXSTYLE, style); + SetWindowLongPtr(hWnd, GWL_EXSTYLE, (IntPtr)style); ExcludeWindowFromPeek(hWnd); } diff --git a/src/ManagedShell.Common/SupportingClasses/ShellWindow.cs b/src/ManagedShell.Common/SupportingClasses/ShellWindow.cs index 673cf624..43679ec8 100644 --- a/src/ManagedShell.Common/SupportingClasses/ShellWindow.cs +++ b/src/ManagedShell.Common/SupportingClasses/ShellWindow.cs @@ -24,9 +24,9 @@ public ShellWindow() CreateHandle(cp); MessageReceived += ShellWndProc; - NativeMethods.SetWindowLong(Handle, NativeMethods.GWL_EXSTYLE, - NativeMethods.GetWindowLong(Handle, NativeMethods.GWL_EXSTYLE) & - ~(int)NativeMethods.ExtendedWindowStyles.WS_EX_NOACTIVATE); + NativeMethods.SetWindowLongPtr(Handle, NativeMethods.GWL_EXSTYLE, + (IntPtr)((int)NativeMethods.GetWindowLongPtr(Handle, NativeMethods.GWL_EXSTYLE) & + ~(int)NativeMethods.ExtendedWindowStyles.WS_EX_NOACTIVATE)); if (NativeMethods.SetShellWindow(Handle) == 1) { diff --git a/src/ManagedShell.Interop/NativeMethods.User32.cs b/src/ManagedShell.Interop/NativeMethods.User32.cs index 97078052..687ab67f 100644 --- a/src/ManagedShell.Interop/NativeMethods.User32.cs +++ b/src/ManagedShell.Interop/NativeMethods.User32.cs @@ -267,7 +267,19 @@ public enum MinimizedMetricsArrangement public delegate IntPtr WndProcDelegate(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam); [DllImport(User32_DllName, SetLastError = true)] - public static extern int GetWindowLong(IntPtr hWnd, int nIndex); + private static extern int GetWindowLong(IntPtr hWnd, int nIndex); + + [DllImport(User32_DllName, EntryPoint = "GetWindowLongPtr", SetLastError = true)] + private static extern IntPtr GetWindowLong64(IntPtr hWnd, int nIndex); + + // This static method is required because Win32 does not support + // GetWindowLongPtr directly + public static IntPtr GetWindowLongPtr(IntPtr hWnd, int nIndex) + { + if (IntPtr.Size == 8) + return GetWindowLong64(hWnd, nIndex); + return (IntPtr)GetWindowLong(hWnd, nIndex); + } [return: MarshalAs(UnmanagedType.Bool)] [DllImport(User32_DllName, SetLastError = true)] @@ -1704,7 +1716,19 @@ public enum WindowShowStyle : uint public static extern bool IsWindowEnabled(IntPtr hWnd); [DllImport(User32_DllName)] - public static extern IntPtr SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong); + private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong); + + [DllImport(User32_DllName, EntryPoint = "SetWindowLongPtr")] + private static extern IntPtr SetWindowLong64(IntPtr hWnd, int nIndex, IntPtr dwNewLong); + + // This static method is required because Win32 does not support + // SetWindowLongPtr directly + public static IntPtr SetWindowLongPtr(IntPtr hWnd, int nIndex, IntPtr dwNewLong) + { + if (IntPtr.Size == 8) + return SetWindowLong64(hWnd, nIndex, dwNewLong); + return (IntPtr)SetWindowLong(hWnd, nIndex, dwNewLong.ToInt32()); + } [DllImport(User32_DllName, SetLastError = true)] public static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId); diff --git a/src/ManagedShell.WindowsTasks/ApplicationWindow.cs b/src/ManagedShell.WindowsTasks/ApplicationWindow.cs index 9baade44..3c7feff2 100644 --- a/src/ManagedShell.WindowsTasks/ApplicationWindow.cs +++ b/src/ManagedShell.WindowsTasks/ApplicationWindow.cs @@ -338,7 +338,7 @@ public int WindowStyles { get { - return NativeMethods.GetWindowLong(Handle, NativeMethods.GWL_STYLE); + return (int)NativeMethods.GetWindowLongPtr(Handle, NativeMethods.GWL_STYLE); } } @@ -346,7 +346,7 @@ public int ExtendedWindowStyles { get { - return NativeMethods.GetWindowLong(Handle, NativeMethods.GWL_EXSTYLE); + return (int)NativeMethods.GetWindowLongPtr(Handle, NativeMethods.GWL_EXSTYLE); } } diff --git a/src/ManagedShell.WindowsTray/TrayService.cs b/src/ManagedShell.WindowsTray/TrayService.cs index de1e0e35..6b39eb1d 100644 --- a/src/ManagedShell.WindowsTray/TrayService.cs +++ b/src/ManagedShell.WindowsTray/TrayService.cs @@ -239,9 +239,9 @@ private IntPtr WndProc(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam) if ((wndPos.flags & SetWindowPosFlags.SWP_SHOWWINDOW) != 0) { - SetWindowLong(HwndTray, GWL_STYLE, - GetWindowLong(HwndTray, GWL_STYLE) & - ~(int)WindowStyles.WS_VISIBLE); + SetWindowLongPtr(HwndTray, GWL_STYLE, + (IntPtr)((int)GetWindowLongPtr(HwndTray, GWL_STYLE) & + ~(int)WindowStyles.WS_VISIBLE)); ShellLogger.Debug($"TrayService: {TrayWndClass} became visible; hiding"); } From 639dc17402bfa4ad0845779a6f1fb0e0b5c4760f Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Sun, 19 Jul 2026 00:02:02 -0500 Subject: [PATCH 2/3] Create enum for GWL flags --- src/ManagedShell.AppBar/FullScreenHelper.cs | 4 ++-- src/ManagedShell.Common/Helpers/WindowHelper.cs | 6 +++--- .../SupportingClasses/ShellWindow.cs | 4 ++-- src/ManagedShell.Interop/NativeMethods.User32.cs | 16 ++++++++++++++-- .../ApplicationWindow.cs | 4 ++-- src/ManagedShell.WindowsTray/TrayService.cs | 4 ++-- 6 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/ManagedShell.AppBar/FullScreenHelper.cs b/src/ManagedShell.AppBar/FullScreenHelper.cs index 5d543360..d3d2c14c 100644 --- a/src/ManagedShell.AppBar/FullScreenHelper.cs +++ b/src/ManagedShell.AppBar/FullScreenHelper.cs @@ -141,7 +141,7 @@ private void updateFullScreenWindows() else { // Still full screen but no longer active - if (((int)GetWindowLongPtr(hWnd, GWL_EXSTYLE) & (int)ExtendedWindowStyles.WS_EX_TOPMOST) == (int)ExtendedWindowStyles.WS_EX_TOPMOST) + if (((int)GetWindowLongPtr(hWnd, (int)WindowLongFlags.GWL_EXSTYLE) & (int)ExtendedWindowStyles.WS_EX_TOPMOST) == (int)ExtendedWindowStyles.WS_EX_TOPMOST) { // If the new foreground window is a topmost window, don't consider this full-screen app inactive continue; @@ -265,7 +265,7 @@ private FullScreenApp getFullScreenApp(IntPtr hWnd, bool fromTasksService = fals private Rect GetEffectiveWindowRect(IntPtr hWnd) { - int style = (int)GetWindowLongPtr(hWnd, GWL_STYLE); + int style = (int)GetWindowLongPtr(hWnd, (int)WindowLongFlags.GWL_STYLE); Rect rect; if ((((int)WindowStyles.WS_CAPTION | (int)WindowStyles.WS_THICKFRAME) & style) == ((int)WindowStyles.WS_CAPTION | (int)WindowStyles.WS_THICKFRAME) || diff --git a/src/ManagedShell.Common/Helpers/WindowHelper.cs b/src/ManagedShell.Common/Helpers/WindowHelper.cs index ced7288f..7749e5aa 100644 --- a/src/ManagedShell.Common/Helpers/WindowHelper.cs +++ b/src/ManagedShell.Common/Helpers/WindowHelper.cs @@ -103,7 +103,7 @@ public static IntPtr GetLowestDesktopChildHwnd() public static void HideWindowFromTasks(IntPtr hWnd) { - int style = (int)GetWindowLongPtr(hWnd, GWL_EXSTYLE) & ~(int)ExtendedWindowStyles.WS_EX_APPWINDOW; + int style = (int)GetWindowLongPtr(hWnd, (int)WindowLongFlags.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. @@ -121,7 +121,7 @@ public static void HideWindowFromTasks(IntPtr hWnd) GetWindowText(hwndOwner, titleBuilder, TITLE_LENGTH + 1); if (titleBuilder.ToString() == "Hidden Window") { - SetWindowLongPtr(hwndOwner, GWL_EXSTYLE, (IntPtr)((int)GetWindowLongPtr(hwndOwner, GWL_EXSTYLE) | (int)ExtendedWindowStyles.WS_EX_TOOLWINDOW)); + SetWindowLongPtr(hwndOwner, (int)WindowLongFlags.GWL_EXSTYLE, (IntPtr)((int)GetWindowLongPtr(hwndOwner, (int)WindowLongFlags.GWL_EXSTYLE) | (int)ExtendedWindowStyles.WS_EX_TOOLWINDOW)); } } } @@ -129,7 +129,7 @@ public static void HideWindowFromTasks(IntPtr hWnd) { style |= (int)ExtendedWindowStyles.WS_EX_TOOLWINDOW; } - SetWindowLongPtr(hWnd, GWL_EXSTYLE, (IntPtr)style); + SetWindowLongPtr(hWnd, (int)WindowLongFlags.GWL_EXSTYLE, (IntPtr)style); ExcludeWindowFromPeek(hWnd); } diff --git a/src/ManagedShell.Common/SupportingClasses/ShellWindow.cs b/src/ManagedShell.Common/SupportingClasses/ShellWindow.cs index 43679ec8..d0470db6 100644 --- a/src/ManagedShell.Common/SupportingClasses/ShellWindow.cs +++ b/src/ManagedShell.Common/SupportingClasses/ShellWindow.cs @@ -24,8 +24,8 @@ public ShellWindow() CreateHandle(cp); MessageReceived += ShellWndProc; - NativeMethods.SetWindowLongPtr(Handle, NativeMethods.GWL_EXSTYLE, - (IntPtr)((int)NativeMethods.GetWindowLongPtr(Handle, NativeMethods.GWL_EXSTYLE) & + NativeMethods.SetWindowLongPtr(Handle, (int)NativeMethods.WindowLongFlags.GWL_EXSTYLE, + (IntPtr)((int)NativeMethods.GetWindowLongPtr(Handle, (int)NativeMethods.WindowLongFlags.GWL_EXSTYLE) & ~(int)NativeMethods.ExtendedWindowStyles.WS_EX_NOACTIVATE)); if (NativeMethods.SetShellWindow(Handle) == 1) diff --git a/src/ManagedShell.Interop/NativeMethods.User32.cs b/src/ManagedShell.Interop/NativeMethods.User32.cs index 687ab67f..85c61045 100644 --- a/src/ManagedShell.Interop/NativeMethods.User32.cs +++ b/src/ManagedShell.Interop/NativeMethods.User32.cs @@ -214,8 +214,20 @@ public enum WindowStyles : uint } public const int MA_NOACTIVATE = 0x0003; - public const int GWL_STYLE = -16; - public const int GWL_EXSTYLE = -20; + + public enum WindowLongFlags : int + { + GWL_EXSTYLE = -20, + GWLP_HINSTANCE = -6, + GWLP_HWNDPARENT = -8, + GWL_ID = -12, + GWL_STYLE = -16, + GWL_USERDATA = -21, + GWL_WNDPROC = -4, + DWLP_USER = 0x8, + DWLP_MSGRESULT = 0x0, + DWLP_DLGPROC = 0x4 + } public const int HSHELL_HIGHBIT = 0x8000; diff --git a/src/ManagedShell.WindowsTasks/ApplicationWindow.cs b/src/ManagedShell.WindowsTasks/ApplicationWindow.cs index 3c7feff2..446c48af 100644 --- a/src/ManagedShell.WindowsTasks/ApplicationWindow.cs +++ b/src/ManagedShell.WindowsTasks/ApplicationWindow.cs @@ -338,7 +338,7 @@ public int WindowStyles { get { - return (int)NativeMethods.GetWindowLongPtr(Handle, NativeMethods.GWL_STYLE); + return (int)NativeMethods.GetWindowLongPtr(Handle, (int)NativeMethods.WindowLongFlags.GWL_STYLE); } } @@ -346,7 +346,7 @@ public int ExtendedWindowStyles { get { - return (int)NativeMethods.GetWindowLongPtr(Handle, NativeMethods.GWL_EXSTYLE); + return (int)NativeMethods.GetWindowLongPtr(Handle, (int)NativeMethods.WindowLongFlags.GWL_EXSTYLE); } } diff --git a/src/ManagedShell.WindowsTray/TrayService.cs b/src/ManagedShell.WindowsTray/TrayService.cs index 6b39eb1d..6ef17200 100644 --- a/src/ManagedShell.WindowsTray/TrayService.cs +++ b/src/ManagedShell.WindowsTray/TrayService.cs @@ -239,8 +239,8 @@ private IntPtr WndProc(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam) if ((wndPos.flags & SetWindowPosFlags.SWP_SHOWWINDOW) != 0) { - SetWindowLongPtr(HwndTray, GWL_STYLE, - (IntPtr)((int)GetWindowLongPtr(HwndTray, GWL_STYLE) & + SetWindowLongPtr(HwndTray, (int)WindowLongFlags.GWL_STYLE, + (IntPtr)((int)GetWindowLongPtr(HwndTray, (int)WindowLongFlags.GWL_STYLE) & ~(int)WindowStyles.WS_VISIBLE)); ShellLogger.Debug($"TrayService: {TrayWndClass} became visible; hiding"); From f16a0dd4b97615611846df4bc283e3fc35490ece Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Sun, 19 Jul 2026 00:26:19 -0500 Subject: [PATCH 3/3] Add convenience function for enum use --- src/ManagedShell.AppBar/FullScreenHelper.cs | 4 ++-- src/ManagedShell.Common/Helpers/WindowHelper.cs | 6 +++--- .../SupportingClasses/ShellWindow.cs | 4 ++-- src/ManagedShell.Interop/NativeMethods.User32.cs | 10 ++++++++++ src/ManagedShell.WindowsTasks/ApplicationWindow.cs | 4 ++-- src/ManagedShell.WindowsTray/TrayService.cs | 4 ++-- 6 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/ManagedShell.AppBar/FullScreenHelper.cs b/src/ManagedShell.AppBar/FullScreenHelper.cs index d3d2c14c..0a8eb87f 100644 --- a/src/ManagedShell.AppBar/FullScreenHelper.cs +++ b/src/ManagedShell.AppBar/FullScreenHelper.cs @@ -141,7 +141,7 @@ private void updateFullScreenWindows() else { // Still full screen but no longer active - if (((int)GetWindowLongPtr(hWnd, (int)WindowLongFlags.GWL_EXSTYLE) & (int)ExtendedWindowStyles.WS_EX_TOPMOST) == (int)ExtendedWindowStyles.WS_EX_TOPMOST) + if (((int)GetWindowLongPtr(hWnd, WindowLongFlags.GWL_EXSTYLE) & (int)ExtendedWindowStyles.WS_EX_TOPMOST) == (int)ExtendedWindowStyles.WS_EX_TOPMOST) { // If the new foreground window is a topmost window, don't consider this full-screen app inactive continue; @@ -265,7 +265,7 @@ private FullScreenApp getFullScreenApp(IntPtr hWnd, bool fromTasksService = fals private Rect GetEffectiveWindowRect(IntPtr hWnd) { - int style = (int)GetWindowLongPtr(hWnd, (int)WindowLongFlags.GWL_STYLE); + int style = (int)GetWindowLongPtr(hWnd, WindowLongFlags.GWL_STYLE); Rect rect; if ((((int)WindowStyles.WS_CAPTION | (int)WindowStyles.WS_THICKFRAME) & style) == ((int)WindowStyles.WS_CAPTION | (int)WindowStyles.WS_THICKFRAME) || diff --git a/src/ManagedShell.Common/Helpers/WindowHelper.cs b/src/ManagedShell.Common/Helpers/WindowHelper.cs index 7749e5aa..7d60306a 100644 --- a/src/ManagedShell.Common/Helpers/WindowHelper.cs +++ b/src/ManagedShell.Common/Helpers/WindowHelper.cs @@ -103,7 +103,7 @@ public static IntPtr GetLowestDesktopChildHwnd() public static void HideWindowFromTasks(IntPtr hWnd) { - int style = (int)GetWindowLongPtr(hWnd, (int)WindowLongFlags.GWL_EXSTYLE) & ~(int)ExtendedWindowStyles.WS_EX_APPWINDOW; + int style = (int)GetWindowLongPtr(hWnd, WindowLongFlags.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. @@ -121,7 +121,7 @@ public static void HideWindowFromTasks(IntPtr hWnd) GetWindowText(hwndOwner, titleBuilder, TITLE_LENGTH + 1); if (titleBuilder.ToString() == "Hidden Window") { - SetWindowLongPtr(hwndOwner, (int)WindowLongFlags.GWL_EXSTYLE, (IntPtr)((int)GetWindowLongPtr(hwndOwner, (int)WindowLongFlags.GWL_EXSTYLE) | (int)ExtendedWindowStyles.WS_EX_TOOLWINDOW)); + SetWindowLongPtr(hwndOwner, WindowLongFlags.GWL_EXSTYLE, (IntPtr)((int)GetWindowLongPtr(hwndOwner, WindowLongFlags.GWL_EXSTYLE) | (int)ExtendedWindowStyles.WS_EX_TOOLWINDOW)); } } } @@ -129,7 +129,7 @@ public static void HideWindowFromTasks(IntPtr hWnd) { style |= (int)ExtendedWindowStyles.WS_EX_TOOLWINDOW; } - SetWindowLongPtr(hWnd, (int)WindowLongFlags.GWL_EXSTYLE, (IntPtr)style); + SetWindowLongPtr(hWnd, WindowLongFlags.GWL_EXSTYLE, (IntPtr)style); ExcludeWindowFromPeek(hWnd); } diff --git a/src/ManagedShell.Common/SupportingClasses/ShellWindow.cs b/src/ManagedShell.Common/SupportingClasses/ShellWindow.cs index d0470db6..7d90dea3 100644 --- a/src/ManagedShell.Common/SupportingClasses/ShellWindow.cs +++ b/src/ManagedShell.Common/SupportingClasses/ShellWindow.cs @@ -24,8 +24,8 @@ public ShellWindow() CreateHandle(cp); MessageReceived += ShellWndProc; - NativeMethods.SetWindowLongPtr(Handle, (int)NativeMethods.WindowLongFlags.GWL_EXSTYLE, - (IntPtr)((int)NativeMethods.GetWindowLongPtr(Handle, (int)NativeMethods.WindowLongFlags.GWL_EXSTYLE) & + NativeMethods.SetWindowLongPtr(Handle, NativeMethods.WindowLongFlags.GWL_EXSTYLE, + (IntPtr)((int)NativeMethods.GetWindowLongPtr(Handle, NativeMethods.WindowLongFlags.GWL_EXSTYLE) & ~(int)NativeMethods.ExtendedWindowStyles.WS_EX_NOACTIVATE)); if (NativeMethods.SetShellWindow(Handle) == 1) diff --git a/src/ManagedShell.Interop/NativeMethods.User32.cs b/src/ManagedShell.Interop/NativeMethods.User32.cs index 85c61045..85197685 100644 --- a/src/ManagedShell.Interop/NativeMethods.User32.cs +++ b/src/ManagedShell.Interop/NativeMethods.User32.cs @@ -284,6 +284,11 @@ public enum MinimizedMetricsArrangement [DllImport(User32_DllName, EntryPoint = "GetWindowLongPtr", SetLastError = true)] private static extern IntPtr GetWindowLong64(IntPtr hWnd, int nIndex); + public static IntPtr GetWindowLongPtr(IntPtr hWnd, WindowLongFlags nIndex) + { + return GetWindowLongPtr(hWnd, (int)nIndex); + } + // This static method is required because Win32 does not support // GetWindowLongPtr directly public static IntPtr GetWindowLongPtr(IntPtr hWnd, int nIndex) @@ -1733,6 +1738,11 @@ public enum WindowShowStyle : uint [DllImport(User32_DllName, EntryPoint = "SetWindowLongPtr")] private static extern IntPtr SetWindowLong64(IntPtr hWnd, int nIndex, IntPtr dwNewLong); + public static IntPtr SetWindowLongPtr(IntPtr hWnd, WindowLongFlags nIndex, IntPtr dwNewLong) + { + return SetWindowLongPtr(hWnd, (int)nIndex, dwNewLong); + } + // This static method is required because Win32 does not support // SetWindowLongPtr directly public static IntPtr SetWindowLongPtr(IntPtr hWnd, int nIndex, IntPtr dwNewLong) diff --git a/src/ManagedShell.WindowsTasks/ApplicationWindow.cs b/src/ManagedShell.WindowsTasks/ApplicationWindow.cs index 446c48af..8a8c74a7 100644 --- a/src/ManagedShell.WindowsTasks/ApplicationWindow.cs +++ b/src/ManagedShell.WindowsTasks/ApplicationWindow.cs @@ -338,7 +338,7 @@ public int WindowStyles { get { - return (int)NativeMethods.GetWindowLongPtr(Handle, (int)NativeMethods.WindowLongFlags.GWL_STYLE); + return (int)NativeMethods.GetWindowLongPtr(Handle, NativeMethods.WindowLongFlags.GWL_STYLE); } } @@ -346,7 +346,7 @@ public int ExtendedWindowStyles { get { - return (int)NativeMethods.GetWindowLongPtr(Handle, (int)NativeMethods.WindowLongFlags.GWL_EXSTYLE); + return (int)NativeMethods.GetWindowLongPtr(Handle, NativeMethods.WindowLongFlags.GWL_EXSTYLE); } } diff --git a/src/ManagedShell.WindowsTray/TrayService.cs b/src/ManagedShell.WindowsTray/TrayService.cs index 6ef17200..d5a95c7d 100644 --- a/src/ManagedShell.WindowsTray/TrayService.cs +++ b/src/ManagedShell.WindowsTray/TrayService.cs @@ -239,8 +239,8 @@ private IntPtr WndProc(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam) if ((wndPos.flags & SetWindowPosFlags.SWP_SHOWWINDOW) != 0) { - SetWindowLongPtr(HwndTray, (int)WindowLongFlags.GWL_STYLE, - (IntPtr)((int)GetWindowLongPtr(HwndTray, (int)WindowLongFlags.GWL_STYLE) & + SetWindowLongPtr(HwndTray, WindowLongFlags.GWL_STYLE, + (IntPtr)((int)GetWindowLongPtr(HwndTray, WindowLongFlags.GWL_STYLE) & ~(int)WindowStyles.WS_VISIBLE)); ShellLogger.Debug($"TrayService: {TrayWndClass} became visible; hiding");