class Program
{
[DllImport("user32", ExactSpelling = true)]
static extern bool EnumWindows(WNDENUMPROC lpEnumFunc, IntPtr lParam);
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
delegate bool WNDENUMPROC(IntPtr hwnd, IntPtr lParam);
static void Main(string[] args)
{
List<IntPtr> windows = new List<IntPtr>();
EnumWindows((hwnd, lParam) =>
{
windows.Add(hwnd);
return true;
}, IntPtr.Zero);
}
}