public static unsafe bool GetMonitorInfo(IntPtr hMonitor, out MonitorInfo lpmi) { lpmi = new MonitorInfo { Size = (uint)sizeof(MonitorInfo) }; return(User32Methods.GetMonitorInfo(hMonitor, ref lpmi)); }
private bool MonitorCallback(IntPtr hMonitor, IntPtr hdc, ref Rect rect, object dwData) { var monitorInfo = new MonitorInfoEx(); monitorInfo.Size = (uint)Marshal.SizeOf(monitorInfo); // Try to get monitor info. if (!User32.GetMonitorInfo(hMonitor, ref monitorInfo)) { return(false); } // Check if the adapter name matches, in which case this is the handle to this monitor. if (monitorInfo.SzDevice == AdapterName) { Handle = hMonitor; } Position = new Vector2(monitorInfo.MonitorRect.Left, monitorInfo.MonitorRect.Top); return(true); }