public static bool TryGetMonitorInfo(this Window window, DefaultWindow defaultWindow, [System.Diagnostics.CodeAnalysis.MaybeNullWhen(true)] out MonitorInfo monitorInfo) #endif { monitorInfo = default; IntPtr monitorHandle = NativeMethods.MonitorFromWindow(window.GetHandle(), defaultWindow); if (monitorHandle == IntPtr.Zero) { return(false); } monitorInfo.Init(); // This MUST be invoked. return(NativeMethods.GetMonitorInfo(monitorHandle, ref monitorInfo)); }
/// <summary> /// Retrieve information about the display monitor for this window. /// </summary> /// <param name="window">Window of interest.</param> /// <param name="defaultWindow">Determines the function's return value if the window does not intersect any display monitor.</param> /// <param name="monitorInfo">Result. Empty when the method returns false.</param> /// <returns>Monitor info for the specified window.</returns> #if NET451 public static bool TryGetMonitorInfo(this Window window, DefaultWindow defaultWindow, out MonitorInfo monitorInfo)