Skip to content

Commit a28d362

Browse files
authored
Merge branch 'master' into master
2 parents 7974269 + cffe1f8 commit a28d362

3 files changed

Lines changed: 15 additions & 5 deletions

File tree

‎FluentFlyoutMSIX/Package.appxmanifest‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<Identity
1212
Name="unchihugo.FluentFlyout"
1313
Publisher="CN=unchihugo"
14-
Version="2.9.0.0" />
14+
Version="2.9.2.0" />
1515

1616
<Properties>
1717
<DisplayName>FluentFlyout</DisplayName>

‎FluentFlyoutWPF/Classes/NativeMethods.cs‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,10 @@ internal struct WindowCompositionAttributeData
256256
[LibraryImport("user32.dll")]
257257
internal static partial uint GetDpiForWindow(IntPtr hMonitor);
258258

259-
[LibraryImport("user32.dll", SetLastError = true)]
260-
[return: MarshalAs(UnmanagedType.Bool)]
261-
internal static partial bool SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int y, int cx, int cy, uint uFlags);
259+
// DllImport instead of LibraryImport for SetWindowPos because for some reason it functions differently when using LibraryImport,
260+
// causing windows to not be topmost and it to be hidden unless you focus on the taskbar.
261+
[DllImport("user32.dll", SetLastError = true)]
262+
internal static extern bool SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int y, int cx, int cy, uint uFlags);
262263

263264
[LibraryImport("user32.dll")]
264265
[return: MarshalAs(UnmanagedType.Bool)]

‎FluentFlyoutWPF/Classes/WindowHelper.cs‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ namespace FluentFlyoutWPF.Classes;
1111

1212
public static class WindowHelper
1313
{
14+
private static readonly NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger();
15+
1416
[StructLayout(LayoutKind.Sequential)]
1517
public struct RECT
1618
{
@@ -52,7 +54,14 @@ public static Rect GetPlacement(Window window) // get the window position, ignor
5254
public static void SetPosition(Window window, double x, double y, bool async = false) // set the position of the window, ignoring WPF
5355
{
5456
var handle = new WindowInteropHelper(window).Handle;
55-
SetWindowPos(handle, 0, (int)x, (int)y, 0, 0, SWP_NOSIZE | SWP_NOZORDER | (async ? SWP_ASYNCWINDOWPOS : (uint)0));
57+
uint flags = SWP_NOSIZE | SWP_NOZORDER | (async ? SWP_ASYNCWINDOWPOS : (uint)0);
58+
bool result = SetWindowPos(handle, 0, (int)x, (int)y, 0, 0, flags);
59+
60+
if (!result)
61+
{
62+
int error = Marshal.GetLastWin32Error();
63+
Logger.Warn($"SetPosition failed for '{window.GetType().Name}' (HWND=0x{handle.ToInt64():X}, X={x}, Y={y}, Flags=0x{flags:X}), Win32Error={error}");
64+
}
5665

5766
return;
5867
}

0 commit comments

Comments
 (0)