예제 #1
0
        public void UpdateDevices()
        {
            List <DisplayAdapter> oldAdapters = Adapters.ToList();
            List <DisplayMonitor> oldMonitors = Monitors.ToList();

            NativeMethods.DISPLAY_DEVICE dev = new NativeMethods.DISPLAY_DEVICE(true);
            uint i = 0;

            while (NativeMethods.EnumDisplayDevices(null, i++, ref dev, 0))
            {
                var adapter = oldAdapters.FirstOrDefault(a => a.DeviceName == dev.DeviceName);
                if (adapter != null)
                {
                    oldAdapters.Remove(adapter);
                    adapter.Init(dev, oldMonitors);
                }
                else
                {
                    adapter = new DisplayAdapter();
                    adapter.Init(dev, oldMonitors);
                    Adapters.Add(adapter);
                }
            }

            var w = new Stopwatch();

            w.Start();

            NativeMethods.EnumDisplayMonitors(IntPtr.Zero, IntPtr.Zero,
                                              delegate(IntPtr hMonitor, IntPtr hdcMonitor, ref NativeMethods.RECT lprcMonitor, IntPtr dwData)
            {
                var mi      = new NativeMethods.MONITORINFOEX(true);
                var success = NativeMethods.GetMonitorInfo(hMonitor, ref mi);
                if (!success)
                {
                    return(true);
                }

                IList monitors = AttachedMonitors.Where(d => d.Adapter.DeviceName == mi.DeviceName).ToList();
                foreach (DisplayMonitor monitor in monitors)
                {
                    monitor.Init(hMonitor, mi);
                    monitor.Timing = w.ElapsedMilliseconds;
                    w.Restart();
                }

                return(true);
            }, IntPtr.Zero);

            DevicesUpdated?.Invoke(this, new EventArgs());

            foreach (var monitor in Monitors)
            {
                Debug.Print(monitor.DeviceName + "\t" + monitor.Edid.Model + "\t" + monitor.Timing);
            }
        }
예제 #2
0
        public void UpdateDevices()
        {
            List <DisplayDevice> oldDevices = Devices.ToList();


            var device = new DisplayDevice(this);

            device.Init(null, new NativeMethods.DISPLAY_DEVICE(true)
            {
                DeviceID = "ROOT", DeviceName = null
            }, oldDevices);

            foreach (var d in oldDevices)
            {
                Devices.Remove(d);
            }

            NativeMethods.EnumDisplayMonitors(IntPtr.Zero, IntPtr.Zero,
                                              delegate(IntPtr hMonitor, IntPtr hdcMonitor, ref NativeMethods.RECT lprcMonitor, IntPtr dwData)
            {
                var mi      = new NativeMethods.MONITORINFOEX(true);
                var success = NativeMethods.GetMonitorInfo(hMonitor, ref mi);
                if (!success)
                {
                    return(true);
                }

                IList monitors = AttachedMonitors.Where(d => d.AttachedDisplay?.DeviceName == mi.DeviceName).ToList();
                foreach (Monitor monitor in monitors)
                {
                    monitor.Init(hMonitor, mi);
                }

                return(true);
            }, IntPtr.Zero);

            DevicesUpdated?.Invoke(this, new EventArgs());
        }