diff --git a/src/ManagedShell.AppBar/FullScreenHelper.cs b/src/ManagedShell.AppBar/FullScreenHelper.cs index 0a8eb87f..12a36353 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, WindowLongFlags.GWL_EXSTYLE) & (int)ExtendedWindowStyles.WS_EX_TOPMOST) == (int)ExtendedWindowStyles.WS_EX_TOPMOST) + if ((GetWindowLong(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; @@ -264,8 +264,8 @@ private FullScreenApp getFullScreenApp(IntPtr hWnd, bool fromTasksService = fals } private Rect GetEffectiveWindowRect(IntPtr hWnd) - { - int style = (int)GetWindowLongPtr(hWnd, WindowLongFlags.GWL_STYLE); + { + int style = GetWindowLong(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 7d60306a..9944d2bc 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, WindowLongFlags.GWL_EXSTYLE) & ~(int)ExtendedWindowStyles.WS_EX_APPWINDOW; + int style = GetWindowLong(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, WindowLongFlags.GWL_EXSTYLE, (IntPtr)((int)GetWindowLongPtr(hwndOwner, WindowLongFlags.GWL_EXSTYLE) | (int)ExtendedWindowStyles.WS_EX_TOOLWINDOW)); + SetWindowLong(hwndOwner, WindowLongFlags.GWL_EXSTYLE, (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, WindowLongFlags.GWL_EXSTYLE, (IntPtr)style); + SetWindowLong(hWnd, WindowLongFlags.GWL_EXSTYLE, style); ExcludeWindowFromPeek(hWnd); } diff --git a/src/ManagedShell.Common/SupportingClasses/ShellWindow.cs b/src/ManagedShell.Common/SupportingClasses/ShellWindow.cs index 7d90dea3..ab51bb41 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.SetWindowLongPtr(Handle, NativeMethods.WindowLongFlags.GWL_EXSTYLE, - (IntPtr)((int)NativeMethods.GetWindowLongPtr(Handle, NativeMethods.WindowLongFlags.GWL_EXSTYLE) & - ~(int)NativeMethods.ExtendedWindowStyles.WS_EX_NOACTIVATE)); + NativeMethods.SetWindowLong(Handle, NativeMethods.WindowLongFlags.GWL_EXSTYLE, + NativeMethods.GetWindowLong(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 85197685..d69a3ebf 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 int GetWindowLong(IntPtr hWnd, WindowLongFlags nIndex) + { + return GetWindowLong(hWnd, (int)nIndex); + } + public static IntPtr GetWindowLongPtr(IntPtr hWnd, WindowLongFlags nIndex) { return GetWindowLongPtr(hWnd, (int)nIndex); @@ -1738,6 +1743,11 @@ public enum WindowShowStyle : uint [DllImport(User32_DllName, EntryPoint = "SetWindowLongPtr")] private static extern IntPtr SetWindowLong64(IntPtr hWnd, int nIndex, IntPtr dwNewLong); + public static int SetWindowLong(IntPtr hWnd, WindowLongFlags nIndex, int dwNewLong) + { + return SetWindowLong(hWnd, (int)nIndex, dwNewLong); + } + public static IntPtr SetWindowLongPtr(IntPtr hWnd, WindowLongFlags nIndex, IntPtr dwNewLong) { return SetWindowLongPtr(hWnd, (int)nIndex, dwNewLong); diff --git a/src/ManagedShell.WindowsTasks/ApplicationWindow.cs b/src/ManagedShell.WindowsTasks/ApplicationWindow.cs index 8a8c74a7..421138ec 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.WindowLongFlags.GWL_STYLE); + return NativeMethods.GetWindowLong(Handle, NativeMethods.WindowLongFlags.GWL_STYLE); } } @@ -346,7 +346,7 @@ public int ExtendedWindowStyles { get { - return (int)NativeMethods.GetWindowLongPtr(Handle, NativeMethods.WindowLongFlags.GWL_EXSTYLE); + return NativeMethods.GetWindowLong(Handle, NativeMethods.WindowLongFlags.GWL_EXSTYLE); } } diff --git a/src/ManagedShell.WindowsTray/TrayService.cs b/src/ManagedShell.WindowsTray/TrayService.cs index d5a95c7d..7b087fa6 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) { - SetWindowLongPtr(HwndTray, WindowLongFlags.GWL_STYLE, - (IntPtr)((int)GetWindowLongPtr(HwndTray, WindowLongFlags.GWL_STYLE) & - ~(int)WindowStyles.WS_VISIBLE)); + SetWindowLong(HwndTray, WindowLongFlags.GWL_STYLE, + GetWindowLong(HwndTray, WindowLongFlags.GWL_STYLE) & + ~(int)WindowStyles.WS_VISIBLE); ShellLogger.Debug($"TrayService: {TrayWndClass} became visible; hiding"); }