Widow

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ HEAD  →  ?path2? @ 1
/trunk/Widow/Helpers.cs/Helpers.cs
@@ -9,52 +9,28 @@
{
#region Public Methods
 
/// <summary> Get the text for the window pointed to by hWnd </summary>
public static string GetWindowText(IntPtr hWnd)
public static IEnumerable<DesktopWindow> GetDesktopWindows()
{
var size = Natives.GetWindowTextLength(hWnd);
if (size > 0)
foreach (var process in Process.GetProcesses())
{
var builder = new StringBuilder(size + 1);
Natives.GetWindowText(hWnd, builder, builder.Capacity);
return builder.ToString();
yield return new DesktopWindow(process.MainWindowHandle, process.MainWindowTitle);
}
 
return string.Empty;
}
 
/// <summary> Find all windows that match the given filter </summary>
/// <param name="filter">
/// A delegate that returns true for windows
/// that should be returned and false for windows that should
/// not be returned
/// </param>
public static IEnumerable<IntPtr> FindWindows(Natives.EnumWindowsProc filter)
public static IntPtr FindWindowByTitle(string name)
{
var windows = new List<IntPtr>();
 
Natives.EnumWindows(delegate(IntPtr wnd, IntPtr param)
var hWnd = IntPtr.Zero;
foreach (var pList in Process.GetProcesses())
{
if (filter(wnd, param))
if (pList.MainWindowTitle.Contains(name))
{
// only add the windows that pass the filter
windows.Add(wnd);
hWnd = pList.MainWindowHandle;
}
}
 
// but return true here so that we iterate all windows
return true;
}, IntPtr.Zero);
 
return windows;
return hWnd;
}
 
public static string GetWindowClass(IntPtr hWnd)
{
var windowClass = new StringBuilder(256);
Natives.GetClassName(hWnd, windowClass, windowClass.Capacity);
return windowClass.ToString();
}
 
public static string GetWindowTitle(IntPtr hWnd)
{
var length = Natives.GetWindowTextLength(hWnd) + 1;
@@ -63,20 +39,6 @@
return title.ToString();
}
 
public static string GetProcessName(IntPtr hWnd)
{
Natives.GetWindowThreadProcessId(hWnd, out var pid);
try
{
var process = Process.GetProcessById((int) pid);
return process.ProcessName;
}
catch
{
return string.Empty;
}
}
 
#endregion
}
}