Exemple #1
0
        public static List <DEVMODE> GetDeviceResolutions(DISPLAY_DEVICE device, DisplaySettingsQueryMode queryMode)
        {
            List <DEVMODE> devModes = new List <DEVMODE>();

            try
            {
                DEVMODE mode = new DEVMODE();
                switch (queryMode)
                {
                case DisplaySettingsQueryMode.QueryCurrentResolution:
                    if (User32.EnumDisplaySettings(device.DeviceName, User32.ENUM_CURRENT_SETTINGS, ref mode))
                    {
                        devModes.Add(mode);
                    }
                    break;

                case DisplaySettingsQueryMode.QueryAllSupported:
                    for (uint i = 0; User32.EnumDisplaySettings(device.DeviceName, i, ref mode); i++)
                    {
                        devModes.Add(mode);
                    }
                    break;

                case DisplaySettingsQueryMode.QueryRegistryResolution:
                    if (User32.EnumDisplaySettings(device.DeviceName, User32.ENUM_REGISTRY_SETTINGS, ref mode))
                    {
                        devModes.Add(mode);
                    }
                    break;
                }
            }
            catch { }
            return(devModes);
        }
        protected override void ProcessRecord()
        {
            DisplaySettingsQueryMode d = DisplaySettingsQueryMode.QueryCurrentResolution;

            switch (QueryMode)
            {
            case "Current": d = DisplaySettingsQueryMode.QueryCurrentResolution; break;

            case "All": d = DisplaySettingsQueryMode.QueryAllSupported; break;

            case "Registry": d = DisplaySettingsQueryMode.QueryRegistryResolution; break;
            }
            foreach (DEVMODE ds in  ScreenDevice.GetDeviceResolutions(ScreenDevice.GetDesktopDeviceByName(DeviceName), d))
            {
                WriteObject(ds);
            }
        }
Exemple #3
0
        static void GetResolution(string[] args)
        {
            string deviceName          = null;
            DisplaySettingsQueryMode d = DisplaySettingsQueryMode.QueryCurrentResolution;

            OptionSet p = new OptionSet()
            {
                {
                    "d|device=", "the {NAME} of the screen device.",
                    v => deviceName = v
                },
                {
                    "o|option=", "the query {OPTION}. (all, current, registry)",
                    v => {
                        switch (v.Trim().ToLower())
                        {
                        case "current": d = DisplaySettingsQueryMode.QueryCurrentResolution; break;

                        case "all": d = DisplaySettingsQueryMode.QueryAllSupported; break;

                        case "registry": d = DisplaySettingsQueryMode.QueryRegistryResolution; break;
                        }
                    }
                }
            };
            List <string> extra;

            try
            {
                extra = p.Parse(args);
            }
            catch (OptionException e)
            {
                Console.WriteLine("ERROR: " + e.Message);
                return;
            }

            if (deviceName == null)
            {
                Console.WriteLine("ERROR: No device name has not been specified.");
                return;
            }

            try
            {
                foreach (DEVMODE ds in ScreenDevice.GetDeviceResolutions(ScreenDevice.GetDesktopDeviceByName(deviceName), d))
                {
                    Console.WriteLine(
                        "{0} x {1}, " +
                        "{2} bit, " +
                        "{3} hertz",
                        ds.dmPelsWidth,
                        ds.dmPelsHeight,
                        ds.dmBitsPerPel,
                        ds.dmDisplayFrequency
                        );
                }
            }
            catch (User32Exception e)
            {
                Console.WriteLine("ERROR: " + e.Message);
                return;
            }
        }