コード例 #1
0
        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);
            }
        }
コード例 #2
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;
            }
        }