/// <summary> /// Retrieves the monitor at the specified native window handle. /// </summary> /// <param name="hwnd"></param> /// <param name="flags"></param> /// <returns></returns> public MonitorInfo GetMonitorFromWindow(IntPtr hwnd, MultiMonFlags flags = MultiMonFlags.DefaultToNearest) { if (Count == 0) { Refresh(); } var h = MonitorFromWindow(hwnd, flags); if (h == IntPtr.Zero) { return(null); } foreach (var m in this) { if (m.hMonitor == h) { return(m); } } return(this[0]); }
/// <summary> /// Retrieves the monitor at the specified WPF window. /// </summary> /// <param name="window"></param> /// <param name="flags"></param> /// <returns></returns> public MonitorInfo GetMonitorFromWindow(System.Windows.Window window, MultiMonFlags flags = MultiMonFlags.DefaultToNearest) { if (Count == 0) { Refresh(); } var ih = new System.Windows.Interop.WindowInteropHelper(window); var h = MonitorFromWindow(ih.EnsureHandle(), flags); ih = null; if (h == IntPtr.Zero) { return(null); } foreach (var m in this) { if (m.hMonitor == h) { return(m); } } return(this[0]); }
private static extern IntPtr MonitorFromRect(W32RECT pt, MultiMonFlags dwFlags);
private static extern IntPtr MonitorFromWindow(IntPtr hWnd, MultiMonFlags dwFlags);
private static extern IntPtr MonitorFromPoint(W32POINT pt, MultiMonFlags dwFlags);