|
2 | 2 | { |
3 | 3 | using System; |
4 | 4 | using System.Drawing; |
| 5 | + using System.Linq; |
5 | 6 | using System.Text; |
6 | 7 | using System.Collections.Generic; |
7 | 8 |
|
@@ -100,21 +101,35 @@ public static NativeWindow GetTopMostWindow() |
100 | 101 | // https://code.msdn.microsoft.com/windowsapps/Enumerate-top-level-9aa9d7c1 |
101 | 102 | // http://stackoverflow.com/a/296014 |
102 | 103 |
|
| 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 | + |
103 | 108 | var results = new List<NativeWindow>(); |
104 | 109 | WinApiInterop.NativeMethods.EnumWindows((hWnd, lParam) => |
105 | 110 | { |
106 | 111 | 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 |
109 | 117 | if ((!window.IsMinimized) && (window.IsVisible)) |
110 | 118 | { |
111 | 119 | 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))) |
115 | 122 | { |
116 | 123 | results.Add(window); |
| 124 | + return true; |
117 | 125 | } |
| 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); |
118 | 133 | } |
119 | 134 |
|
120 | 135 | return true; |
|
0 commit comments