How do I collect all windows handlers in C#. I need all the windows (not just the parents) Thanks,
Asked
Active
Viewed 237 times
0
-
Can you please elaborate the scenario, what exactly you are looking for ? – VJOY Jan 31 '10 at 14:39
-
In general I have a window handler and I would like to check if it has blocking dialog so I'm looking for a window that my window is the parent, and has WS_EX_DLGMODALFRAME style. – Guy Jan 31 '10 at 15:22
1 Answers
3
Try the following utility class. Given a handle to a window it will return all of the associated child windows.
public class WindowFinder
{
private class Helper
{
internal List<IntPtr> Windows = new List<IntPtr>();
internal bool ProcessWindow(IntPtr handle, IntPtr parameter)
{
Windows.Add(handle);
return true;
}
}
private delegate bool EnumWindowProc(IntPtr hWnd, IntPtr parameter);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool EnumChildWindows(IntPtr hwndParent, EnumWindowProc lpEnumFunc, IntPtr lParam);
public static List<IntPtr> GetChildWindows(IntPtr parentWindow)
{
var helper = new Helper();
EnumChildWindows(parentWindow, helper.ProcessWindow, IntPtr.Zero);
return helper.Windows;
}
}

JaredPar
- 733,204
- 149
- 1,241
- 1,454