private (MONITORINFO mi, string device) GetMonitorInfoEx(IntPtr hMonitor) { unsafe { MONITORINFOEXW miEx = default; MONITORINFO * pmi = (MONITORINFO *)&miEx; (*pmi).cbSize = (uint)sizeof(MONITORINFOEXW); if (!NativeMethods.GetMonitorInfo(new(hMonitor), pmi)) { try { throw new Win32Exception().WithMessage($"Could not read the monitor information for HMONITOR={hMonitor:X8}!"); } catch (Win32Exception e) when(e.IsInvalidMonitorHandleException() || !IsMonitorValid(hMonitor)) { throw new InvalidDisplayReferenceException(hMonitor, e); } } char *pszDevice = (char *)&miEx.szDevice; return(*pmi, new string(pszDevice)); } }
public static extern BOOL GetMonitorInfoW(HMONITOR hMonitor, MONITORINFO *lpmi);