diff --git a/src/Files.App.CsWin32/NativeMethods.txt b/src/Files.App.CsWin32/NativeMethods.txt
index 68837251b7f1..681c690b0587 100644
--- a/src/Files.App.CsWin32/NativeMethods.txt
+++ b/src/Files.App.CsWin32/NativeMethods.txt
@@ -160,3 +160,5 @@ IApplicationDocumentLists
ApplicationDocumentLists
IApplicationActivationManager
MENU_ITEM_TYPE
+WM_WINDOWPOSCHANGING
+WINDOWPOS
diff --git a/src/Files.App.CsWin32/Windows.Win32.Extras.cs b/src/Files.App.CsWin32/Windows.Win32.Extras.cs
index e626c5390633..c12b9bc62569 100644
--- a/src/Files.App.CsWin32/Windows.Win32.Extras.cs
+++ b/src/Files.App.CsWin32/Windows.Win32.Extras.cs
@@ -16,51 +16,5 @@ namespace UI.WindowsAndMessaging
{
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
public delegate LRESULT WNDPROC(HWND hWnd, uint msg, WPARAM wParam, LPARAM lParam);
-
- /// Contains information about the size and position of a window.
- ///
- /// Learn more about this API from docs.microsoft.com.
- ///
- public partial struct WINDOWPOS
- {
- ///
- /// Type: HWND A handle to the window.
- /// Read more on docs.microsoft.com.
- ///
- internal HWND hwnd;
-
- ///
- /// Type: HWND The position of the window in Z order (front-to-back position). This member can be a handle to the window behind which this window is placed, or can be one of the special values listed with the SetWindowPos function.
- /// Read more on docs.microsoft.com.
- ///
- internal HWND hwndInsertAfter;
-
- ///
- /// Type: int The position of the left edge of the window.
- /// Read more on docs.microsoft.com.
- ///
- internal int x;
-
- ///
- /// Type: int The position of the top edge of the window.
- /// Read more on docs.microsoft.com.
- ///
- internal int y;
-
- ///
- /// Type: int The window width, in pixels.
- /// Read more on docs.microsoft.com.
- ///
- internal int cx;
-
- ///
- /// Type: int The window height, in pixels.
- /// Read more on docs.microsoft.com.
- ///
- internal int cy;
-
- /// Type: UINT
- public SET_WINDOW_POS_FLAGS flags;
- }
}
}
diff --git a/src/Files.App/MainWindow.xaml.cs b/src/Files.App/MainWindow.xaml.cs
index 3f08fdfbb482..142382c34dad 100644
--- a/src/Files.App/MainWindow.xaml.cs
+++ b/src/Files.App/MainWindow.xaml.cs
@@ -357,10 +357,9 @@ public bool SetCanWindowToFront(bool canWindowToFront)
}
}
- private const int WM_WINDOWPOSCHANGING = 0x0046;
private void WindowManager_WindowMessageReceived(object? sender, WinUIEx.Messaging.WindowMessageEventArgs e)
{
- if ((!CanWindowToFront) && e.Message.MessageId == WM_WINDOWPOSCHANGING)
+ if ((!CanWindowToFront) && e.Message.MessageId == Windows.Win32.PInvoke.WM_WINDOWPOSCHANGING)
{
Win32Helper.ForceWindowPosition(e.Message.LParam);
e.Handled = true;
diff --git a/src/Files.App/Views/Layouts/BaseLayoutPage.cs b/src/Files.App/Views/Layouts/BaseLayoutPage.cs
index 0acc0707a171..180bc8c0c907 100644
--- a/src/Files.App/Views/Layouts/BaseLayoutPage.cs
+++ b/src/Files.App/Views/Layouts/BaseLayoutPage.cs
@@ -1014,6 +1014,7 @@ protected virtual void FileList_DragItemsStarting(object sender, DragItemsStarti
e.Data.SetStorageItems(storageItemList, false);
}
+ // Set can window to front (#13255)
MainWindow.Instance.SetCanWindowToFront(false);
itemDragging = true;
}
@@ -1025,9 +1026,9 @@ protected virtual void FileList_DragItemsStarting(object sender, DragItemsStarti
protected virtual void FileList_DragItemsCompleted(ListViewBase sender, DragItemsCompletedEventArgs args)
{
+ // Set can window to front (#13255)
itemDragging = false;
MainWindow.Instance.SetCanWindowToFront(true);
- // No need to bring the window to the front
}
private void Item_DragLeave(object sender, DragEventArgs e)
@@ -1159,9 +1160,9 @@ protected void FileList_ContainerContentChanging(ListViewBase sender, ContainerC
RefreshContainer(args.ItemContainer, args.InRecycleQueue);
RefreshItem(args.ItemContainer, args.Item, args.InRecycleQueue, args);
+ // Set can window to front (#13255)
itemDragging = false;
MainWindow.Instance.SetCanWindowToFront(true);
- // No need to bring the window to the front
}
private void RefreshContainer(SelectorItem container, bool inRecycleQueue)
@@ -1216,7 +1217,7 @@ private void RefreshItem(SelectorItem container, object item, bool inRecycleQueu
protected internal void FileListItem_PointerPressed(object sender, PointerRoutedEventArgs e)
{
- // Set can window to front and bring the window to the front if necessary
+ // Set can window to front and bring the window to the front if necessary (#13255)
if ((!itemDragging) && MainWindow.Instance.SetCanWindowToFront(true))
Win32Helper.BringToForegroundEx(new(MainWindow.Instance.WindowHandle));
@@ -1245,7 +1246,7 @@ protected internal void FileListItem_PointerPressed(object sender, PointerRouted
protected internal void FileListItem_PointerEntered(object sender, PointerRoutedEventArgs e)
{
- // Set can window to front before the item is dragged
+ // Set can window to front (#13255)
if (sender is SelectorItem selectorItem && selectorItem.IsSelected)
MainWindow.Instance.SetCanWindowToFront(false);
@@ -1295,7 +1296,7 @@ selectedItems is not null &&
protected internal void FileListItem_PointerExited(object sender, PointerRoutedEventArgs e)
{
- // Set can window to front
+ // Set can window to front (#13255)
if (!itemDragging)
MainWindow.Instance.SetCanWindowToFront(true);
@@ -1308,21 +1309,21 @@ protected internal void FileListItem_PointerExited(object sender, PointerRoutedE
protected void FileListItem_Tapped(object sender, TappedRoutedEventArgs e)
{
- // Set can window to front and bring the window to the front if necessary
+ // Set can window to front and bring the window to the front if necessary (#13255)
if ((!itemDragging) && MainWindow.Instance.SetCanWindowToFront(true))
Win32Helper.BringToForegroundEx(new(MainWindow.Instance.WindowHandle));
}
protected void FileListItem_DoubleTapped(object sender, DoubleTappedRoutedEventArgs e)
{
- // Set can window to front and bring the window to the front if necessary
+ // Set can window to front and bring the window to the front if necessary (#13255)
if ((!itemDragging) && MainWindow.Instance.SetCanWindowToFront(true))
Win32Helper.BringToForegroundEx(new(MainWindow.Instance.WindowHandle));
}
protected void FileListItem_RightTapped(object sender, RightTappedRoutedEventArgs e)
{
- // Set can window to front and bring the window to the front if necessary
+ // Set can window to front and bring the window to the front if necessary (#13255)
if ((!itemDragging) && MainWindow.Instance.SetCanWindowToFront(true))
Win32Helper.BringToForegroundEx(new(MainWindow.Instance.WindowHandle));