Widow
/trunk/Widow/Helpers.cs |
@@ -48,6 +48,19 @@ |
return windows; |
} |
|
public static IEnumerable<IntPtr> EnumerateWindows() |
{ |
var windows = new List<IntPtr>(); |
|
Natives.EnumWindows(delegate(IntPtr wnd, IntPtr param) |
{ |
windows.Add(wnd); |
return true; |
}, IntPtr.Zero); |
|
return windows; |
} |
|
/// <summary> Find all windows that contain the given title text </summary> |
/// <param name="titleText"> The text that the window title must contain. </param> |
public static IEnumerable<IntPtr> FindWindowsWithText(string titleText) |
@@ -63,14 +76,13 @@ |
return title.ToString(); |
} |
|
#endregion |
|
public static string GetProcessName(IntPtr hWnd) |
{ |
Natives.GetWindowThreadProcessId(hWnd, out var pid); |
var process = Process.GetProcessById((int)pid); |
var process = Process.GetProcessById((int) pid); |
return process.ProcessName; |
} |
|
} |
#endregion |
} |
} |
/trunk/Widow/Natives.cs |
@@ -1534,10 +1534,6 @@ |
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] |
public static extern int GetWindowTextLength(IntPtr hWnd); |
|
#endregion |
|
#region Private Methods |
|
[DllImport("user32.dll", SetLastError = true)] |
public static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint processId); |
|
/trunk/Widow/WindowManipulation.cs |
@@ -1,4 +1,5 @@ |
using System; |
using System.Collections.Generic; |
using System.Linq; |
using System.Threading; |
using System.Threading.Tasks; |
@@ -68,7 +69,8 @@ |
WindowsToManipulate = windowsToManipulate; |
} |
|
public WindowManipulation(MainForm mainForm, Windows.Windows windowsToManipulate, Settings settings) : this(mainForm, |
public WindowManipulation(MainForm mainForm, Windows.Windows windowsToManipulate, Settings settings) : this( |
mainForm, |
windowsToManipulate) |
{ |
OnWindowCreate = settings.OnWindowCreate; |
@@ -102,7 +104,7 @@ |
return; |
} |
|
if (!WindowsToManipulate.Contains(e.Title)) |
if (!WindowsToManipulate.TryGetWindow(e.Title, out _)) |
{ |
return; |
} |
@@ -116,7 +118,25 @@ |
|
public async Task Apply() |
{ |
await Task.WhenAll(WindowsToManipulate.Window.Select(window => WindowsBufferBlock.SendAsync(window))); |
var windows = new List<Window>(); |
foreach (var hWnd in Helpers.EnumerateWindows()) |
{ |
var title = Helpers.GetWindowTitle(hWnd); |
|
if (string.IsNullOrEmpty(title)) |
{ |
continue; |
} |
|
if (!WindowsToManipulate.TryGetWindow(title, out var window)) |
{ |
continue; |
} |
|
windows.Add(window); |
} |
|
await Task.WhenAll(windows.Select(window => WindowsBufferBlock.SendAsync(window))); |
} |
|
#endregion |
/trunk/Windows/Windows.cs |
@@ -27,19 +27,19 @@ |
} |
|
_window.CollectionChanged -= Window_CollectionChanged; |
|
_window.Clear(); |
|
_windows.Clear(); |
foreach (var window in value) |
{ |
_window.Add(window); |
|
if (_windows.Contains(window.Title)) |
if (_windows.ContainsKey(window.Title)) |
{ |
continue; |
} |
|
_windows.Add(window.Title); |
_windows.Add(window.Title, window); |
} |
|
_window.CollectionChanged += Window_CollectionChanged; |
@@ -53,7 +53,7 @@ |
|
private readonly ObservableCollection<Window> _window = new ObservableCollection<Window>(); |
|
private readonly HashSet<string> _windows = new HashSet<string>(); |
private readonly Dictionary<string, Window> _windows = new Dictionary<string, Window>(); |
|
#endregion |
|
@@ -86,7 +86,7 @@ |
{ |
foreach (var window in e.OldItems.OfType<Window>()) |
{ |
if (_windows.Contains(window.Title)) |
if (_windows.ContainsKey(window.Title)) |
{ |
_windows.Remove(window.Title); |
} |
@@ -98,9 +98,9 @@ |
{ |
foreach (var window in e.NewItems.OfType<Window>()) |
{ |
if (!_windows.Contains(window.Title)) |
if (!_windows.ContainsKey(window.Title)) |
{ |
_windows.Add(window.Title); |
_windows.Add(window.Title, window); |
} |
} |
} |
@@ -110,9 +110,9 @@ |
|
#region Public Methods |
|
public bool Contains(string hash) |
public bool TryGetWindow(string title, out Window window) |
{ |
return _windows.Contains(hash); |
return _windows.TryGetValue(title, out window); |
} |
|
#endregion |