public static List <IntPtr> EnumWindows() { try { List <IntPtr> items = new List <IntPtr>(); EnumWindowsProcD CallBackPtr = new EnumWindowsProcD(EnumWindowsProc); GCHandle hItems = GCHandle.Alloc(items); IntPtr lItems = GCHandle.ToIntPtr(hItems); EnumWindows(CallBackPtr, ref lItems); return(items); } catch (Exception ex) { throw new Exception("An error occured during window enumeration: " + ex.Message); } }
public static extern bool EnumWindows(EnumWindowsProcD lpEnumFunc, ref IntPtr lParam);