Skip to content

Commit 2990914

Browse files
committed
Name magic numbers
1 parent 58236ed commit 2990914

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

‎PopGuard/Detection/Win32Windows.cs‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ namespace PopGuard;
99
/// </summary>
1010
internal static class Win32Windows
1111
{
12+
// A top-level window smaller than this (in pixels) is treated as an auxiliary/hidden helper
13+
// window and not reported.
14+
private const int MinReasonableWidth = 40;
15+
private const int MinReasonableHeight = 20;
16+
17+
// Win32 window class names are at most 256 characters.
18+
private const int MaxClassNameLength = 256;
19+
1220
/// <summary>Enumerate the handles of visible top-level windows.</summary>
1321
public static List<IntPtr> EnumerateVisibleTopLevel()
1422
{
@@ -34,7 +42,7 @@ public static bool IsReasonableSize(IntPtr hwnd)
3442
{
3543
return false;
3644
}
37-
return (r.Right - r.Left) >= 40 && (r.Bottom - r.Top) >= 20;
45+
return (r.Right - r.Left) >= MinReasonableWidth && (r.Bottom - r.Top) >= MinReasonableHeight;
3846
}
3947

4048
public static string ProcessName(IntPtr hwnd)
@@ -77,7 +85,7 @@ public static string Title(IntPtr hwnd)
7785

7886
public static string ClassName(IntPtr hwnd)
7987
{
80-
var sb = new StringBuilder(256);
88+
var sb = new StringBuilder(MaxClassNameLength);
8189
int n = NativeMethods.GetClassName(hwnd, sb, sb.Capacity);
8290
return n > 0 ? sb.ToString() : string.Empty;
8391
}

0 commit comments

Comments
 (0)