From 6db722624912c1155e3932ecdaca7c0a313ec693 Mon Sep 17 00:00:00 2001 From: Peter Kirmeier Date: Sat, 12 Nov 2022 19:31:47 +0100 Subject: [PATCH] Fix 32bit support --- NativeDllImport/ShowWindow.cs | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/NativeDllImport/ShowWindow.cs b/NativeDllImport/ShowWindow.cs index 2a70ea1..b26d91f 100644 --- a/NativeDllImport/ShowWindow.cs +++ b/NativeDllImport/ShowWindow.cs @@ -26,23 +26,46 @@ namespace SystemTrayMenu.DllImports { WindowInteropHelper wndHelper = new WindowInteropHelper(window); - int exStyle = (int)GetWindowLongPtr(wndHelper.Handle, GWL_EXSTYLE); - exStyle |= WS_EX_TOOLWINDOW; // do not show when user presses alt + tab - SetWindowLongPtr(wndHelper.Handle, GWL_EXSTYLE, (IntPtr)exStyle); + if (Environment.Is64BitProcess) + { + long exStyle = (long)GetWindowLongPtr(wndHelper.Handle, GWL_EXSTYLE); + exStyle |= WS_EX_TOOLWINDOW; // do not show when user presses alt + tab + SetWindowLongPtr(wndHelper.Handle, GWL_EXSTYLE, (IntPtr)exStyle); + } + else + { + int exStyle = (int)GetWindowLong(wndHelper.Handle, GWL_EXSTYLE); + exStyle |= WS_EX_TOOLWINDOW; // do not show when user presses alt + tab + SetWindowLong(wndHelper.Handle, GWL_EXSTYLE, (IntPtr)exStyle); + } } + /// + /// https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getwindowlongw . + /// + [SupportedOSPlatform("windows")] + [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)] + private static extern IntPtr GetWindowLong(IntPtr hWnd, int nIndex); + /// /// https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getwindowlongptrw . /// [SupportedOSPlatform("windows")] - [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)] + [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)] private static extern IntPtr GetWindowLongPtr(IntPtr hWnd, int nIndex); + /// + /// https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwindowlongw . + /// + [SupportedOSPlatform("windows")] + [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)] + private static extern IntPtr SetWindowLong(IntPtr hWnd, int nIndex, IntPtr dwNewLong); + /// /// https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwindowlongptrw . /// [SupportedOSPlatform("windows")] - [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)] + [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)] private static extern IntPtr SetWindowLongPtr(IntPtr hWnd, int nIndex, IntPtr dwNewLong); } }