コード例 #1
0
        /// <summary>
        /// 获取系统支持的分辨率
        /// </summary>
        public static Size[] GetSystemResolutions()
        {
            List <Size> list = new List <Size>();

            var devmode = new User32.DEVMODE();

            devmode.dmDeviceName = new string(new char[32]);
            devmode.dmFormName   = new string(new char[32]);
            devmode.dmSize       = (short)Marshal.SizeOf(devmode);

            int i = 0, displayWidth = 0;

            while (User32.EnumDisplaySettings(null, i, ref devmode) == 1)
            {
                if (devmode.dmPelsWidth >= 800 && displayWidth != devmode.dmPelsWidth)
                {
                    displayWidth = devmode.dmPelsWidth;
                    list.Add(new Size {
                        Width = (short)devmode.dmPelsWidth, Height = (short)devmode.dmPelsHeight
                    });
                }
                i++;
            }
            list.Reverse();
            return(list.ToArray());
        }
コード例 #2
0
        internal DisplaySettingsInfo(User32.DEVMODE devMode)
        {
            // Do not log here, it will result in too much stuff (GetSupported create all supported display
            //   settings :  can be in thousand, often in hundreds)

            if (devMode.dmSize == 0)
            {
                throw new ArgumentNullException("devMode", "Must be a valid instance of the struct (uninitialized struct passed in)");
            }
            _devMode = devMode;
        }
コード例 #3
0
        public static IReadOnlyList <ResolutionEntry> GetResolutions()
        {
            if (InitializeAcVideoModes())
            {
                try {
                    return(AcVideoModes.GetResolutionEntries().ToList());
                } catch (Exception e) {
                    NonfatalError.Notify(ToolsStrings.AcSettings_CannotGetResolutions, e);
                }
            }

            var d = new User32.DEVMODE();

            return(LinqExtension.RangeFrom()
                   .Select(i => User32.EnumDisplaySettings(null, i, ref d)
                                        ? new ResolutionEntry(i + 1, d.dmPelsWidth, d.dmPelsHeight, d.dmDisplayFrequency) : null)
                   .TakeWhile(x => x != null).Distinct().ToList());
        }
コード例 #4
0
ファイル: DisplaySettings.cs プロジェクト: dotnet/wpf-test
        private DisplaySettingsInfo[] SupportedConfiguration()
        {
            if (_supported == null)
            {
                List <DisplaySettingsInfo> retVal = new List <DisplaySettingsInfo>();
                bool success = true;
                uint index   = 0;
                while (success)
                {
                    User32.DEVMODE devMode = new User32.DEVMODE();
                    devMode.dmSize = (short)Marshal.SizeOf(devMode);
                    success        = User32.EnumDisplaySettings(_deviceName, index++, ref devMode);
                    if (success)
                    {
                        retVal.Add(new DisplaySettingsInfo(devMode));
                    }
                }
                _supported = retVal.ToArray();
            }

            return(_supported);
        }
コード例 #5
0
        public static int CurrentRefreshRate()
        {
            var vDevMode = new User32.DEVMODE();

            return(User32.EnumDisplaySettings(null, User32.ENUM_CURRENT_SETTINGS, ref vDevMode) ? vDevMode.dmDisplayFrequency : 60);
        }