Skip to content

Commit 2a343ee

Browse files
authored
Code Quality: Replaced private const & struct with CsWin32 & Improve comments (#16556)
1 parent 29a3ce5 commit 2a343ee

File tree

4 files changed

+12
-56
lines changed

4 files changed

+12
-56
lines changed

src/Files.App.CsWin32/NativeMethods.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,5 @@ IApplicationDocumentLists
160160
ApplicationDocumentLists
161161
IApplicationActivationManager
162162
MENU_ITEM_TYPE
163+
WM_WINDOWPOSCHANGING
164+
WINDOWPOS

src/Files.App.CsWin32/Windows.Win32.Extras.cs

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -16,51 +16,5 @@ namespace UI.WindowsAndMessaging
1616
{
1717
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
1818
public delegate LRESULT WNDPROC(HWND hWnd, uint msg, WPARAM wParam, LPARAM lParam);
19-
20-
/// <summary>Contains information about the size and position of a window.</summary>
21-
/// <remarks>
22-
/// <para><see href="https://learn.microsoft.com/windows/win32/api/winuser/ns-winuser-windowpos">Learn more about this API from docs.microsoft.com</see>.</para>
23-
/// </remarks>
24-
public partial struct WINDOWPOS
25-
{
26-
/// <summary>
27-
/// <para>Type: <b>HWND</b> A handle to the window.</para>
28-
/// <para><see href="https://learn.microsoft.com/windows/win32/api/winuser/ns-winuser-windowpos#members">Read more on docs.microsoft.com</see>.</para>
29-
/// </summary>
30-
internal HWND hwnd;
31-
32-
/// <summary>
33-
/// <para>Type: <b>HWND</b> 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 <a href="https://docs.microsoft.com/windows/desktop/api/winuser/nf-winuser-setwindowpos">SetWindowPos</a> function.</para>
34-
/// <para><see href="https://learn.microsoft.com/windows/win32/api/winuser/ns-winuser-windowpos#members">Read more on docs.microsoft.com</see>.</para>
35-
/// </summary>
36-
internal HWND hwndInsertAfter;
37-
38-
/// <summary>
39-
/// <para>Type: <b>int</b> The position of the left edge of the window.</para>
40-
/// <para><see href="https://learn.microsoft.com/windows/win32/api/winuser/ns-winuser-windowpos#members">Read more on docs.microsoft.com</see>.</para>
41-
/// </summary>
42-
internal int x;
43-
44-
/// <summary>
45-
/// <para>Type: <b>int</b> The position of the top edge of the window.</para>
46-
/// <para><see href="https://learn.microsoft.com/windows/win32/api/winuser/ns-winuser-windowpos#members">Read more on docs.microsoft.com</see>.</para>
47-
/// </summary>
48-
internal int y;
49-
50-
/// <summary>
51-
/// <para>Type: <b>int</b> The window width, in pixels.</para>
52-
/// <para><see href="https://learn.microsoft.com/windows/win32/api/winuser/ns-winuser-windowpos#members">Read more on docs.microsoft.com</see>.</para>
53-
/// </summary>
54-
internal int cx;
55-
56-
/// <summary>
57-
/// <para>Type: <b>int</b> The window height, in pixels.</para>
58-
/// <para><see href="https://learn.microsoft.com/windows/win32/api/winuser/ns-winuser-windowpos#members">Read more on docs.microsoft.com</see>.</para>
59-
/// </summary>
60-
internal int cy;
61-
62-
/// <summary>Type: <b>UINT</b></summary>
63-
public SET_WINDOW_POS_FLAGS flags;
64-
}
6519
}
6620
}

src/Files.App/MainWindow.xaml.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,10 +357,9 @@ public bool SetCanWindowToFront(bool canWindowToFront)
357357
}
358358
}
359359

360-
private const int WM_WINDOWPOSCHANGING = 0x0046;
361360
private void WindowManager_WindowMessageReceived(object? sender, WinUIEx.Messaging.WindowMessageEventArgs e)
362361
{
363-
if ((!CanWindowToFront) && e.Message.MessageId == WM_WINDOWPOSCHANGING)
362+
if ((!CanWindowToFront) && e.Message.MessageId == Windows.Win32.PInvoke.WM_WINDOWPOSCHANGING)
364363
{
365364
Win32Helper.ForceWindowPosition(e.Message.LParam);
366365
e.Handled = true;

src/Files.App/Views/Layouts/BaseLayoutPage.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,7 @@ protected virtual void FileList_DragItemsStarting(object sender, DragItemsStarti
10141014
e.Data.SetStorageItems(storageItemList, false);
10151015
}
10161016

1017+
// Set can window to front (#13255)
10171018
MainWindow.Instance.SetCanWindowToFront(false);
10181019
itemDragging = true;
10191020
}
@@ -1025,9 +1026,9 @@ protected virtual void FileList_DragItemsStarting(object sender, DragItemsStarti
10251026

10261027
protected virtual void FileList_DragItemsCompleted(ListViewBase sender, DragItemsCompletedEventArgs args)
10271028
{
1029+
// Set can window to front (#13255)
10281030
itemDragging = false;
10291031
MainWindow.Instance.SetCanWindowToFront(true);
1030-
// No need to bring the window to the front
10311032
}
10321033

10331034
private void Item_DragLeave(object sender, DragEventArgs e)
@@ -1159,9 +1160,9 @@ protected void FileList_ContainerContentChanging(ListViewBase sender, ContainerC
11591160
RefreshContainer(args.ItemContainer, args.InRecycleQueue);
11601161
RefreshItem(args.ItemContainer, args.Item, args.InRecycleQueue, args);
11611162

1163+
// Set can window to front (#13255)
11621164
itemDragging = false;
11631165
MainWindow.Instance.SetCanWindowToFront(true);
1164-
// No need to bring the window to the front
11651166
}
11661167

11671168
private void RefreshContainer(SelectorItem container, bool inRecycleQueue)
@@ -1216,7 +1217,7 @@ private void RefreshItem(SelectorItem container, object item, bool inRecycleQueu
12161217

12171218
protected internal void FileListItem_PointerPressed(object sender, PointerRoutedEventArgs e)
12181219
{
1219-
// Set can window to front and bring the window to the front if necessary
1220+
// Set can window to front and bring the window to the front if necessary (#13255)
12201221
if ((!itemDragging) && MainWindow.Instance.SetCanWindowToFront(true))
12211222
Win32Helper.BringToForegroundEx(new(MainWindow.Instance.WindowHandle));
12221223

@@ -1245,7 +1246,7 @@ protected internal void FileListItem_PointerPressed(object sender, PointerRouted
12451246

12461247
protected internal void FileListItem_PointerEntered(object sender, PointerRoutedEventArgs e)
12471248
{
1248-
// Set can window to front before the item is dragged
1249+
// Set can window to front (#13255)
12491250
if (sender is SelectorItem selectorItem && selectorItem.IsSelected)
12501251
MainWindow.Instance.SetCanWindowToFront(false);
12511252

@@ -1295,7 +1296,7 @@ selectedItems is not null &&
12951296

12961297
protected internal void FileListItem_PointerExited(object sender, PointerRoutedEventArgs e)
12971298
{
1298-
// Set can window to front
1299+
// Set can window to front (#13255)
12991300
if (!itemDragging)
13001301
MainWindow.Instance.SetCanWindowToFront(true);
13011302

@@ -1308,21 +1309,21 @@ protected internal void FileListItem_PointerExited(object sender, PointerRoutedE
13081309

13091310
protected void FileListItem_Tapped(object sender, TappedRoutedEventArgs e)
13101311
{
1311-
// Set can window to front and bring the window to the front if necessary
1312+
// Set can window to front and bring the window to the front if necessary (#13255)
13121313
if ((!itemDragging) && MainWindow.Instance.SetCanWindowToFront(true))
13131314
Win32Helper.BringToForegroundEx(new(MainWindow.Instance.WindowHandle));
13141315
}
13151316

13161317
protected void FileListItem_DoubleTapped(object sender, DoubleTappedRoutedEventArgs e)
13171318
{
1318-
// Set can window to front and bring the window to the front if necessary
1319+
// Set can window to front and bring the window to the front if necessary (#13255)
13191320
if ((!itemDragging) && MainWindow.Instance.SetCanWindowToFront(true))
13201321
Win32Helper.BringToForegroundEx(new(MainWindow.Instance.WindowHandle));
13211322
}
13221323

13231324
protected void FileListItem_RightTapped(object sender, RightTappedRoutedEventArgs e)
13241325
{
1325-
// Set can window to front and bring the window to the front if necessary
1326+
// Set can window to front and bring the window to the front if necessary (#13255)
13261327
if ((!itemDragging) && MainWindow.Instance.SetCanWindowToFront(true))
13271328
Win32Helper.BringToForegroundEx(new(MainWindow.Instance.WindowHandle));
13281329

0 commit comments

Comments
 (0)