Skip to content

Commit 16298be

Browse files
committed
Better filtering of topmost window by class name
1 parent 644896d commit 16298be

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

Src/ScreenGrid.Models/AppsInterop/NativeWindow.cs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{
33
using System;
44
using System.Drawing;
5+
using System.Linq;
56
using System.Text;
67
using System.Collections.Generic;
78

@@ -100,21 +101,35 @@ public static NativeWindow GetTopMostWindow()
100101
// https://code.msdn.microsoft.com/windowsapps/Enumerate-top-level-9aa9d7c1
101102
// http://stackoverflow.com/a/296014
102103

104+
var ClassNamesWhiteList = new[] { PhotoViewerWindow.MainWindowClassName, "IEFrame", "Chrome_WidgetWin_1", "MozillaWindowClass", "TLister", };
105+
var ClassNamesBlackList = new[] { "Shell_TrayWnd", "Button", "Alternate Owner", };
106+
var ClassNamesPartialBlackList = new[] { "ScreenGrid", "HwndWrapper", };
107+
103108
var results = new List<NativeWindow>();
104109
WinApiInterop.NativeMethods.EnumWindows((hWnd, lParam) =>
105110
{
106111
var window = new NativeWindow(hWnd);
107-
108-
// Skip some
112+
113+
// TODO: better checks for inappropriate windows
114+
// TODO: test in another environments
115+
116+
// Skip inappropriate windows
109117
if ((!window.IsMinimized) && (window.IsVisible))
110118
{
111119
var className = window.ClassName;
112-
// TODO: better checks for inappropriate windows
113-
if ((className != "Shell_TrayWnd") && (className != "Button") && (!className.Contains("ScreenGrid")) &&
114-
(!className.Contains("HwndWrapper")))
120+
121+
if (ClassNamesWhiteList.Any(s => (String.Compare(s, className, StringComparison.Ordinal) == 0)))
115122
{
116123
results.Add(window);
124+
return true;
117125
}
126+
else if ((ClassNamesBlackList.Any(s => (String.Compare(s, className, StringComparison.Ordinal) == 0))) ||
127+
(ClassNamesPartialBlackList.Any(s => (className.Contains(s)))))
128+
{
129+
return true;
130+
}
131+
132+
results.Add(window);
118133
}
119134

120135
return true;

0 commit comments

Comments
 (0)