forked from AlexanderPro/SmartSystemMenu
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnumWindows.cs
More file actions
68 lines (57 loc) · 1.83 KB
/
Copy pathEnumWindows.cs
File metadata and controls
68 lines (57 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System;
using System.Collections.Generic;
using System.Linq;
using SmartSystemMenu.Settings;
using SmartSystemMenu.Native;
namespace SmartSystemMenu
{
static class EnumWindows
{
private static string[] _filterTitles;
private static IList<Window> _windows;
private static SmartSystemMenuSettings _settings;
private static WindowSettings _windowSettings;
public static IList<Window> EnumAllWindows(SmartSystemMenuSettings settings, WindowSettings windowSettings, params string[] filterTitles)
{
_filterTitles = filterTitles ?? new string[0];
_windows = new List<Window>();
_settings = settings;
_windowSettings = windowSettings;
User32.EnumWindows(EnumWindowCallback, 0);
return _windows;
}
private static bool EnumWindowCallback(IntPtr hwnd, int lParam)
{
if (_windows.Any(w => w.Handle == hwnd))
{
return true;
}
int pid;
bool isAdd;
User32.GetWindowThreadProcessId(hwnd, out pid);
#if WIN32
isAdd = !Environment.Is64BitOperatingSystem || SystemUtils.IsWow64Process(pid);
#else
isAdd = Environment.Is64BitOperatingSystem && !SystemUtils.IsWow64Process(pid);
#endif
if (!isAdd)
{
return true;
}
var window = new Window(hwnd, _settings.MenuItems, _settings.Language);
if (!window.Menu.Exists)
{
isAdd = false;
}
if (_filterTitles.Any(s => window.GetWindowText() == s))
{
isAdd = false;
}
if (isAdd)
{
_windows.Add(window);
}
return true;
}
}
}