From f5b8047968154f58f50766734a4e327f5958e690 Mon Sep 17 00:00:00 2001 From: Lamparter <71598437+Lamparter@users.noreply.github.com> Date: Sun, 2 Feb 2025 17:08:38 +0000 Subject: [PATCH 1/2] Specify `SetWindowLong` for x86 configuration --- src/Files.App.CsWin32/Files.App.CsWin32.csproj | 1 + src/Files.App.CsWin32/NativeMethods.txt | 1 + src/Files.App.CsWin32/Windows.Win32.Extras.cs | 12 ++++++++++++ src/Files.App/Data/Items/WindowEx.cs | 2 +- .../UserControls/Previews/ShellPreviewViewModel.cs | 4 ++-- 5 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Files.App.CsWin32/Files.App.CsWin32.csproj b/src/Files.App.CsWin32/Files.App.CsWin32.csproj index 2a1d7733b97e..35e03e5d0025 100644 --- a/src/Files.App.CsWin32/Files.App.CsWin32.csproj +++ b/src/Files.App.CsWin32/Files.App.CsWin32.csproj @@ -11,6 +11,7 @@ win-x86;win-x64;win-arm64 TRACE;DEBUG;NETFX_CORE TRACE;RELEASE;NETFX_CORE + $(DefineConstants);$(Platform) true diff --git a/src/Files.App.CsWin32/NativeMethods.txt b/src/Files.App.CsWin32/NativeMethods.txt index c521ed9b183b..86837b295466 100644 --- a/src/Files.App.CsWin32/NativeMethods.txt +++ b/src/Files.App.CsWin32/NativeMethods.txt @@ -99,6 +99,7 @@ SendMessage IsWindowVisible COPYDATASTRUCT SetWindowLongPtr +SetWindowLong GetDpiForWindow CallWindowProc MINMAXINFO diff --git a/src/Files.App.CsWin32/Windows.Win32.Extras.cs b/src/Files.App.CsWin32/Windows.Win32.Extras.cs index 048d8d1f7681..fdb0fa60345b 100644 --- a/src/Files.App.CsWin32/Windows.Win32.Extras.cs +++ b/src/Files.App.CsWin32/Windows.Win32.Extras.cs @@ -17,4 +17,16 @@ namespace UI.WindowsAndMessaging [UnmanagedFunctionPointer(CallingConvention.Winapi)] public delegate LRESULT WNDPROC(HWND hWnd, uint msg, WPARAM wParam, LPARAM lParam); } + + public static partial class PInvoke + { + public static nint SetWindowLongPlat(HWND hWnd, UI.WindowsAndMessaging.WINDOW_LONG_PTR_INDEX nIndex, nint dwNewLong) + { +#if x86 + return SetWindowLong(hWnd, nIndex, (int)dwNewLong); +#else + return SetWindowLongPtr(hWnd, nIndex, dwNewLong); +#endif + } + } } diff --git a/src/Files.App/Data/Items/WindowEx.cs b/src/Files.App/Data/Items/WindowEx.cs index 782788918989..b1cf044cb990 100644 --- a/src/Files.App/Data/Items/WindowEx.cs +++ b/src/Files.App/Data/Items/WindowEx.cs @@ -102,7 +102,7 @@ public unsafe WindowEx(int minWidth = 400, int minHeight = 300) _newWndProc = new(NewWindowProc); var pNewWndProc = Marshal.GetFunctionPointerForDelegate(_newWndProc); - var pOldWndProc = PInvoke.SetWindowLongPtr(new(WindowHandle), WINDOW_LONG_PTR_INDEX.GWL_WNDPROC, pNewWndProc); + var pOldWndProc = PInvoke.SetWindowLongPlat(new(WindowHandle), WINDOW_LONG_PTR_INDEX.GWL_WNDPROC, pNewWndProc); _oldWndProc = Marshal.GetDelegateForFunctionPointer(pOldWndProc); Closed += WindowEx_Closed; diff --git a/src/Files.App/ViewModels/UserControls/Previews/ShellPreviewViewModel.cs b/src/Files.App/ViewModels/UserControls/Previews/ShellPreviewViewModel.cs index c001531701fa..1c866363dc4b 100644 --- a/src/Files.App/ViewModels/UserControls/Previews/ShellPreviewViewModel.cs +++ b/src/Files.App/ViewModels/UserControls/Previews/ShellPreviewViewModel.cs @@ -249,11 +249,11 @@ public unsafe void PointerEntered(bool onPreview) (uint)Marshal.SizeOf(dwAttrib)); if (isOfficePreview) - PInvoke.SetWindowLongPtr(new((nint)hwnd), WINDOW_LONG_PTR_INDEX.GWL_EXSTYLE, 0); + PInvoke.SetWindowLongPlat(new((nint)hwnd), WINDOW_LONG_PTR_INDEX.GWL_EXSTYLE, 0); } else { - PInvoke.SetWindowLongPtr(new((nint)hwnd), WINDOW_LONG_PTR_INDEX.GWL_EXSTYLE, (nint)(WINDOW_EX_STYLE.WS_EX_LAYERED | WINDOW_EX_STYLE.WS_EX_COMPOSITED)); + PInvoke.SetWindowLongPlat(new((nint)hwnd), WINDOW_LONG_PTR_INDEX.GWL_EXSTYLE, (nint)(WINDOW_EX_STYLE.WS_EX_LAYERED | WINDOW_EX_STYLE.WS_EX_COMPOSITED)); var dwAttrib = Convert.ToUInt32(true); From 7bfae6615de7a6662c7b9ad9a4a0ccf344a65829 Mon Sep 17 00:00:00 2001 From: Lamparter <71598437+Lamparter@users.noreply.github.com> Date: Sun, 2 Feb 2025 17:09:11 +0000 Subject: [PATCH 2/2] Fix indentation --- src/Files.App.CsWin32/Files.App.CsWin32.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Files.App.CsWin32/Files.App.CsWin32.csproj b/src/Files.App.CsWin32/Files.App.CsWin32.csproj index 35e03e5d0025..1f60d2e9e4fc 100644 --- a/src/Files.App.CsWin32/Files.App.CsWin32.csproj +++ b/src/Files.App.CsWin32/Files.App.CsWin32.csproj @@ -11,7 +11,7 @@ win-x86;win-x64;win-arm64 TRACE;DEBUG;NETFX_CORE TRACE;RELEASE;NETFX_CORE - $(DefineConstants);$(Platform) + $(DefineConstants);$(Platform) true