Exemplo n.º 1
0
        private IEnumerable <Monitor> EnumerateMonitors(NativeMethods.DISPLAY_DEVICE displayDevice)
        {
            for (uint id = 0; NativeMethods.EnumDisplayDevices(null, id, ref displayDevice, 0); id++)
            {
                if (!displayDevice.StateFlags.HasFlag(NativeMethods.DisplayDeviceStateFlags.AttachedToDesktop))
                {
                    continue;
                }

                NativeMethods.DEVMODE ds = new NativeMethods.DEVMODE();

                bool suc2 = NativeMethods.EnumDisplaySettings(displayDevice.DeviceName, NativeMethods.ENUM_CURRENT_SETTINGS,
                                                              ref ds);
                if (!suc2)
                {
                    Logger.Error("failed to enumerate current settings for display {InternalName}", displayDevice.DeviceName);
                    continue;
                }

                Monitor heliosMonitor = new Monitor(ConvertPixels(ds.dmPositionX),
                                                    ConvertPixels(ds.dmPositionY),
                                                    ConvertPixels(ds.dmPelsWidth),
                                                    ConvertPixels(ds.dmPelsHeight),
                                                    ds.dmDisplayOrientation);

                // check this assumption that we make throughout the code: we identify the main display by its coordinates being
                // 0,0 at the top left
                Debug.Assert(displayDevice.StateFlags.HasFlag(NativeMethods.DisplayDeviceStateFlags.PrimaryDevice) ==
                             heliosMonitor.IsPrimaryDisplay);

                yield return(heliosMonitor);
            }
        }
Exemplo n.º 2
0
        private Monitor CreateHeliosMonitor(NativeMethods.DISPLAY_DEVICE displayDevice)
        {
            NativeMethods.DEVMODE deviceMode = new NativeMethods.DEVMODE();

            bool suc2 = NativeMethods.EnumDisplaySettings(displayDevice.DeviceName, NativeMethods.ENUM_CURRENT_SETTINGS,
                                                          ref deviceMode);

            if (!suc2)
            {
                Logger.Error("failed to enumerate current settings for display {InternalName}", displayDevice.DeviceName);
                return(null);
            }

            Monitor heliosMonitor = new Monitor(ConvertPixels(deviceMode.dmPositionX),
                                                ConvertPixels(deviceMode.dmPositionY),
                                                ConvertPixels(deviceMode.dmPelsWidth),
                                                ConvertPixels(deviceMode.dmPelsHeight),
                                                deviceMode.dmDisplayOrientation);

            Logger.Debug("Created Helios Monitor for display {Name} of size {Width}x{Height} at {Left},{Top}",
                         displayDevice.DeviceName,
                         heliosMonitor.Width,
                         heliosMonitor.Height,
                         heliosMonitor.Left,
                         heliosMonitor.Top);

            // check this assumption that we make throughout the code: we identify the main display by its coordinates being
            // 0,0 at the top left
            Debug.Assert(displayDevice.StateFlags.HasFlag(NativeMethods.DisplayDeviceStateFlags.PrimaryDevice) ==
                         heliosMonitor.IsPrimaryDisplay);
            return(heliosMonitor);
        }
Exemplo n.º 3
0
 private IEnumerable <NativeMethods.DISPLAY_DEVICE> EnumerateDisplays()
 {
     NativeMethods.DISPLAY_DEVICE displayDevice = new NativeMethods.DISPLAY_DEVICE();
     displayDevice.cb = Marshal.SizeOf(displayDevice);
     for (uint id = 0; NativeMethods.EnumDisplayDevices(null, id, ref displayDevice, 0); id++)
     {
         yield return(displayDevice);
     }
 }
Exemplo n.º 4
0
 private NativeMethods.DISPLAY_DEVICE LogDisplayDevice(NativeMethods.DISPLAY_DEVICE displayDevice)
 {
     Logger.Debug("Windows reporting display {Name} with id {Id} and key {Key} with string {String}",
                  displayDevice.DeviceName,
                  displayDevice.DeviceID,
                  displayDevice.DeviceKey,
                  displayDevice.DeviceString);
     return(displayDevice);
 }