Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/ManagedShell.AppBar/FullScreenHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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, 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;
Expand Down Expand Up @@ -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, WindowLongFlags.GWL_STYLE);
Rect rect;

if ((((int)WindowStyles.WS_CAPTION | (int)WindowStyles.WS_THICKFRAME) & style) == ((int)WindowStyles.WS_CAPTION | (int)WindowStyles.WS_THICKFRAME) ||
Expand Down
6 changes: 3 additions & 3 deletions src/ManagedShell.Common/Helpers/WindowHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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, 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.
Expand All @@ -121,15 +121,15 @@ 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, WindowLongFlags.GWL_EXSTYLE, (IntPtr)((int)GetWindowLongPtr(hwndOwner, WindowLongFlags.GWL_EXSTYLE) | (int)ExtendedWindowStyles.WS_EX_TOOLWINDOW));
}
}
}
else
{
style |= (int)ExtendedWindowStyles.WS_EX_TOOLWINDOW;
}
SetWindowLong(hWnd, GWL_EXSTYLE, style);
SetWindowLongPtr(hWnd, WindowLongFlags.GWL_EXSTYLE, (IntPtr)style);

ExcludeWindowFromPeek(hWnd);
}
Expand Down
6 changes: 3 additions & 3 deletions src/ManagedShell.Common/SupportingClasses/ShellWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.WindowLongFlags.GWL_EXSTYLE,
(IntPtr)((int)NativeMethods.GetWindowLongPtr(Handle, NativeMethods.WindowLongFlags.GWL_EXSTYLE) &
~(int)NativeMethods.ExtendedWindowStyles.WS_EX_NOACTIVATE));

if (NativeMethods.SetShellWindow(Handle) == 1)
{
Expand Down
54 changes: 50 additions & 4 deletions src/ManagedShell.Interop/NativeMethods.User32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -267,7 +279,24 @@ 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);

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)
{
if (IntPtr.Size == 8)
return GetWindowLong64(hWnd, nIndex);
return (IntPtr)GetWindowLong(hWnd, nIndex);
}

[return: MarshalAs(UnmanagedType.Bool)]
[DllImport(User32_DllName, SetLastError = true)]
Expand Down Expand Up @@ -1704,7 +1733,24 @@ 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);

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)
{
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);
Expand Down
4 changes: 2 additions & 2 deletions src/ManagedShell.WindowsTasks/ApplicationWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -338,15 +338,15 @@ public int WindowStyles
{
get
{
return NativeMethods.GetWindowLong(Handle, NativeMethods.GWL_STYLE);
return (int)NativeMethods.GetWindowLongPtr(Handle, NativeMethods.WindowLongFlags.GWL_STYLE);
}
}

public int ExtendedWindowStyles
{
get
{
return NativeMethods.GetWindowLong(Handle, NativeMethods.GWL_EXSTYLE);
return (int)NativeMethods.GetWindowLongPtr(Handle, NativeMethods.WindowLongFlags.GWL_EXSTYLE);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/ManagedShell.WindowsTray/TrayService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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, WindowLongFlags.GWL_STYLE,
(IntPtr)((int)GetWindowLongPtr(HwndTray, WindowLongFlags.GWL_STYLE) &
~(int)WindowStyles.WS_VISIBLE));

ShellLogger.Debug($"TrayService: {TrayWndClass} became visible; hiding");
}
Expand Down