Skip to content

Commit

Permalink
Fix SetWindowLong for x86 #803 (#825)
Browse files Browse the repository at this point in the history
* Fix #803

* Move declarations

* Update if statement

* Update marshall declaration

---------

Co-authored-by: pomianowski <[email protected]>
  • Loading branch information
ghost1372 and pomianowski authored Nov 22, 2023
1 parent ecf7c00 commit 01e464f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/Wpf.Ui/Interop/UnsafeNativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,10 @@ public static bool RemoveWindowTitlebarContents(IntPtr handle)
var windowStyleLong = User32.GetWindowLong(handle, User32.GWL.GWL_STYLE);
windowStyleLong &= ~(int)User32.WS.SYSMENU;

var result = User32.SetWindowLong(handle, User32.GWL.GWL_STYLE, windowStyleLong);
IntPtr result = SetWindowLong(handle, User32.GWL.GWL_STYLE, windowStyleLong);
long resultValue = result.ToInt64();

return result > 0x0;
return resultValue > 0x0;
}

/// <summary>
Expand Down Expand Up @@ -519,4 +520,14 @@ private static bool GetHandle(Window? window, out IntPtr windowHandle)

return windowHandle != IntPtr.Zero;
}

private static IntPtr SetWindowLong(IntPtr handle, User32.GWL nIndex, long windowStyleLong)
{
if (IntPtr.Size == 4)
{
return new IntPtr(User32.SetWindowLong(handle, (int)nIndex, (int)windowStyleLong));
}

return User32.SetWindowLongPtr(handle, (int)nIndex, (IntPtr)windowStyleLong);
}
}
6 changes: 6 additions & 0 deletions src/Wpf.Ui/Interop/User32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1308,6 +1308,12 @@ [In] IntPtr lParam
[DllImport(Libraries.User32, CharSet = CharSet.Auto)]
public static extern IntPtr SetWindowLongPtr([In] IntPtr hWnd, [In] int nIndex, [In] IntPtr dwNewLong);

/// <summary>
/// Changes an attribute of the specified window.
/// </summary>
[DllImport(Libraries.User32, CharSet = CharSet.Auto, SetLastError = true)]
public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);

/// <summary>
/// Destroys an icon and frees any memory the icon occupied.
/// </summary>
Expand Down

0 comments on commit 01e464f

Please sign in to comment.