Widow

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 11  →  ?path2? @ 12
/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