public List<Resolution> GetResolutions()
        {
            if (_modes == null)
            {
                _modes = new List<Resolution>();
                List<string> addedModes = new List<string>();
                int i = 0;

                DEVMODE dm = new DEVMODE();
                dm.dmDeviceName = new String(new char[32]);
                dm.dmFormName = new String(new char[32]);
                dm.dmSize = (short)Marshal.SizeOf(dm);

                while (0 != NativeMethods.EnumDisplaySettings(null, i, ref dm))
                {
                    if (dm.dmBitsPerPel == 32 || dm.dmBitsPerPel == 16)
                    {
                        Resolution r = new Resolution(dm.dmPelsWidth, dm.dmPelsHeight, dm.dmDisplayFrequency, (dm.dmDisplayFlags & NativeMethods.DM_INTERLACED) == NativeMethods.DM_INTERLACED, dm.dmDisplayFixedOutput, dm.dmBitsPerPel);
                        if (!addedModes.Contains(r.ToString()))
                        {
                            _modes.Add(r);
                            addedModes.Add(r.ToString());
                        }
                    }
                    i++;
                }
            }

            return _modes;
        }
Exemplo n.º 2
0
        public DisplayManager()
        {
            mode = new DEVMODE();
            mode.dmSize = (ushort)Marshal.SizeOf(mode);

            EnumDisplaySettings(null, ENUM_CURRENT_SETTINGS, ref mode);
        }
Exemplo n.º 3
0
 //���ص�ǰͼ��ģʽ��Ϣ
 public DEVMODE getResolution()
 {
     DEVMODE dm = new DEVMODE();
     dm.dmSize = (short)Marshal.SizeOf(typeof(DEVMODE));
     bool mybool;
     mybool = EnumDisplaySettings(null, -1, ref dm);
     return dm;
 }
Exemplo n.º 4
0
 public static string DevmodeToString(DEVMODE devMode)
 {
     return devMode.dmPelsWidth.ToString() +
     " x " + devMode.dmPelsHeight.ToString() +
     ", " + devMode.dmBitsPerPel.ToString() +
     " bits, " +
     devMode.dmDisplayFrequency.ToString() + " Hz";
 }
Exemplo n.º 5
0
 public void ResetDisplay()
 {
     long RetVal = 0;
     DEVMODE dm = new DEVMODE();
     dm.dmSize = (short)Marshal.SizeOf(typeof(DEVMODE));
     dm.dmPelsWidth = x1;
     dm.dmPelsHeight = y1;
     dm.dmDisplayFrequency = 60;
     dm.dmFields = DEVMODE.DM_PELSWIDTH | DEVMODE.DM_PELSHEIGHT | DEVMODE.DM_DISPLAYFREQUENCY;
     RetVal = ChangeDisplaySettings(ref dm, 0);
 }
Exemplo n.º 6
0
        public static void SetMode(int w,int h)
        {
            DEVMODE devMode = new DEVMODE();

            devMode.dmSize			= (short)Marshal.SizeOf(devMode);
            devMode.dmPelsWidth		= w;
            devMode.dmPelsHeight	= h;
            devMode.dmFields		= (int)(DispChangeField.DM_PELSWIDTH | DispChangeField.DM_PELSHEIGHT);

            ChangeDisplaySettings(ref devMode, 0);
        }
Exemplo n.º 7
0
        // http://www.dotnetspark.com/kb/1948-change-display-settings-programmatically.aspx
        private static DEVMODE? GetCurrentSettings()
        {
            DEVMODE mode = new DEVMODE();
            mode.dmSize = (short)Marshal.SizeOf(mode);

            if (EnumDisplaySettings(null, ENUM_CURRENT_SETTINGS, ref mode) == true) // Succeeded
            {
                return mode;
            }
            else return null;
        }
Exemplo n.º 8
0
        internal ChangeResolution()
        {
            EnumDevices();

            if (_deviceModeNum == -1)
            {
                throw new Exception("Main display device not found");
            }

            _originalResolution = GetDevmode(_deviceModeNum, -1);
        }
Exemplo n.º 9
0
 /// <summary>
 /// 设置屏幕分辨率
 /// </summary>
 /// <param name="Width">宽度</param>
 /// <param name="Height">高度</param>
 public static void ChangeRes(int Width, int Height)
 {
     DEVMODE DevM = new DEVMODE();
     DevM.dmSize = (short)Marshal.SizeOf(typeof(DEVMODE));
     bool mybool;
     mybool = EnumDisplaySettings(null, 0, ref DevM);
     DevM.dmPelsWidth = Width;//宽
     DevM.dmPelsHeight = Height;//高
     DevM.dmDisplayFrequency = 60;//刷新频率
     DevM.dmBitsPerPel = 32;//颜色象素
     long result = ChangeDisplaySettings(ref DevM, 0);
 }
        public static Resolution GetCurrentResolution()
        {
            DEVMODE cDm = new DEVMODE();
            //cDm.dmDeviceName = new String(new char[32]);
            //cDm.dmFormName = new String(new char[32]);
            cDm.dmSize = (short)Marshal.SizeOf(cDm);

            NativeMethods.EnumDisplaySettings(null, NativeMethods.ENUM_CURRENT_SETTINGS, ref cDm);

            Resolution res = new Resolution(cDm.dmPelsWidth, cDm.dmPelsHeight, cDm.dmDisplayFrequency, ((cDm.dmDisplayFlags & NativeMethods.DM_INTERLACED) == NativeMethods.DM_INTERLACED), cDm.dmDisplayFixedOutput, cDm.dmBitsPerPel);

            return res;
        }
Exemplo n.º 11
0
 //��������֧��ͼ��ģʽ
 public List<DEVMODE> getAllResolution()
 {
     List<DEVMODE> allMode = new List<DEVMODE>();
     DEVMODE dm = new DEVMODE();
     dm.dmSize = (short)Marshal.SizeOf(typeof(DEVMODE));
     int index = 0;
     while (EnumDisplaySettings(null, index, ref dm))
     {
         allMode.Add(dm);
         index++;
     }
     return allMode;
 }
 public static void GetResolutions()
 {
     DEVMODE vDevMode = new DEVMODE();
     int i = 0;
     while (EnumDisplaySettings(null, i, ref vDevMode))
     {
         Console.WriteLine("Width:{0} Height:{1} Color:{2} Frequency:{3}",
                                 vDevMode.dmPelsWidth,
                                 vDevMode.dmPelsHeight,
                                 1 << vDevMode.dmBitsPerPel, vDevMode.dmDisplayFrequency
                             );
         i++;
     }
 }
Exemplo n.º 13
0
        public static List<Size> GetResolutions()
        {
            List<Size> results = new List<Size>();

            DEVMODE vDevMode = new DEVMODE();
            int i = 0;

            while (EnumDisplaySettings(null, i, ref vDevMode))
            {
                results.Add(new Size(vDevMode.dmPelsWidth, vDevMode.dmPelsHeight));
                i++;
            }

            return results;
        }
Exemplo n.º 14
0
        public void FindValidDisplayModes()
        {
            int dMode = -1;
            AvailScrRes = new List<DEVMODE>();

            DEVMODE DM = new DEVMODE();
            DM.dmSize = (short)Marshal.SizeOf(DM);
            DM.dmFields = (int)(DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL);
            while (User32.EnumDisplaySettings(null, dMode, ref DM) > 0)
            {
                AvailScrRes.Add(DM);
                dMode++;
            }

            piAvailableDisplayModes = AvailScrRes.Count;
        }
Exemplo n.º 15
0
        public static Dictionary <string, NativeMethods> GetResolutions()
        {
            Dictionary <string, NativeMethods> resolutions = new Dictionary <string, NativeMethods>();

            DISPLAY_DEVICE dd = new DISPLAY_DEVICE();

            dd.cb = Marshal.SizeOf(typeof(DISPLAY_DEVICE));

            uint deviceNum = 0;

            while (EnumDisplayDevices(null, deviceNum, ref dd, 0))
            {
                //DumpDevice(dd);
                DEVMODE dm = new DEVMODE();
                dm.dmDeviceName = new string(new char[32]);
                dm.dmFormName   = new string(new char[32]);
                dm.dmSize       = (short)Marshal.SizeOf(dm);
                if (0 != EnumDisplaySettings(dd.DeviceName, ENUM_CURRENT_SETTINGS, ref dm))
                {
                    //We have a monitor, and here's the resolution.
                    //Debug.WriteLine(dd.DeviceName + ", " + dm.dmPelsWidth);
                    resolutions[dd.DeviceName] = new NativeMethods {
                        x = dm.dmPelsWidth, y = dm.dmPelsHeight, offsetX = dm.dmPosition.x, offsetY = dm.dmPosition.y
                    };
                }

                DISPLAY_DEVICE newdd = new DISPLAY_DEVICE();
                newdd.cb = Marshal.SizeOf(typeof(DISPLAY_DEVICE));
                uint monitorNum = 0;
                while (EnumDisplayDevices(dd.DeviceName, monitorNum, ref newdd, 0))
                {
                    //DumpDevice(newdd);

                    if (0 != EnumDisplaySettings(newdd.DeviceName, ENUM_CURRENT_SETTINGS, ref dm))
                    {
                        //Usually don't find monitors here
                        Debug.WriteLine("found a monitor here?");
                    }
                    monitorNum++;
                }
                deviceNum++;
            }

            return(resolutions);
        }
Exemplo n.º 16
0
        private static Rectangle GetWindowsDisplaySize()
        {
            var left   = 0;
            var right  = 0;
            var top    = 0;
            var bottom = 0;
            var width  = 0;
            var height = 0;
            // Enumerate system display devices
            var devIdx = 0;

            while (true)
            {
                var deviceData = new DisplayDevice {
                    cb = Marshal.SizeOf(typeof(DisplayDevice))
                };
                if (EnumDisplayDevices(null, devIdx, ref deviceData, 0) != 0)
                {
                    // Get the position and size of this particular display device
                    var devMode = new DEVMODE();
                    if (EnumDisplaySettings(deviceData.DeviceName, EnumCurrentSettings, ref devMode))
                    {
                        // Update the virtual screen dimensions
                        left   = Math.Min(left, devMode.dmPositionX);
                        top    = Math.Min(top, devMode.dmPositionY);
                        right  = Math.Max(right, devMode.dmPositionX + devMode.dmPelsWidth);
                        bottom = Math.Max(bottom, devMode.dmPositionY + devMode.dmPelsHeight);
                        width  = left - right;
                        height = top - bottom;
                    }

                    devIdx++;
                }
                else
                {
                    break;
                }
            }

            width  = Math.Abs(width);
            height = Math.Abs(height);
            var rect = new Rectangle(left, top, width, height);

            return(rect);
        }
Exemplo n.º 17
0
        public ConfigViewModel()
        {
            // Set default SilkCfg.dat
            m_SilkCfg = new SilkCfg();

            // Load available resolutions to display
            SupportedResolutions = new List <SilkCfg.WindowResolution>();
            DEVMODE mode      = new DEVMODE();
            var     minPixels = 800 * 600;

            for (int i = 0; EnumDisplaySettings(null, i, ref mode); i++)
            {
                // Avoid lowest resolutions
                if (mode.dmPelsWidth * mode.dmPelsHeight < minPixels)
                {
                    continue;
                }
                // Add only one per resolution
                var resolution = new SilkCfg.WindowResolution((uint)mode.dmPelsWidth, (uint)mode.dmPelsHeight);
                if (!SupportedResolutions.Contains(resolution))
                {
                    SupportedResolutions.Add(resolution);
                }
            }
            // Default brightness
            SupportedBrightness = new List <SilkCfg.Brightness>()
            {
                SilkCfg.Brightness.VeryDark,
                SilkCfg.Brightness.Dark,
                SilkCfg.Brightness.Normal,
                SilkCfg.Brightness.Bright,
                SilkCfg.Brightness.VeryBright
            };
            // Default graphics
            SupportedGraphics = new List <SilkCfg.Graphic>()
            {
                SilkCfg.Graphic.Low,
                SilkCfg.Graphic.Middle,
                SilkCfg.Graphic.High
            };
            // Set default SROptionSet.dat
            m_SROptionSet = new SROptionSet();
            // Set languages supported
            SupportedLanguages = new List <string>(LauncherSettings.CLIENT_LANGUAGE_SUPPORTED_MASK);
        }
Exemplo n.º 18
0
 /// <summary>
 /// 当前系统支持的分辨率列表
 /// </summary>
 /// <returns></returns>
 private static List<Size> CurenScrennSettingList()
 {
     List<Size> CurenSetList = new List<Size>();
     int i = -1;
     string str = string.Empty;
     List<string> ls = new List<string>();
     DEVMODE DevM = new DEVMODE();
     bool mybool;
     mybool = EnumDisplaySettings(null, i, ref DevM);
     while (mybool)
     {
         i = i + 1;
         Size cuSize = new Size(DevM.dmPelsWidth, DevM.dmPelsHeight);
         CurenSetList.Add(cuSize);
         mybool = EnumDisplaySettings(null, i, ref DevM);
     }
     return CurenSetList;
 }
Exemplo n.º 19
0
    public static List <(string key, DEVMODE value)> GetScreenInfo()
    {
        DEVMODE devMode = new DEVMODE();

        //HashSet<string> datas = new HashSet<string>();
        List <(string key, DEVMODE value)> devModes = new List <(string key, DEVMODE value)>();
        int index = 0;

        while (User_32.EnumDisplaySettings(null, index, ref devMode) != 0)
        {
            var str = $"{devMode.dmPelsWidth}*{devMode.dmPelsHeight}@{devMode.dmDisplayFrequency}Hz";
            //datas.Add(str);
            devModes.Add((str, devMode));
            index++;
        }

        return(devModes);
    }
Exemplo n.º 20
0
 //���÷ֱ���,width��,height��,displayFrequencyˢ��Ƶ��,���óɹ�����true,����false
 //���÷�ʽ�� setResolution(1024, 768, 75);
 public bool setResolution(int width, int height, int displayFrequency)
 {
     bool ret = false;
     long RetVal = 0;
     DEVMODE dm = new DEVMODE();
     dm.dmSize = (short)Marshal.SizeOf(typeof(DEVMODE));
     dm.dmPelsWidth = width;
     dm.dmPelsHeight = height;
     dm.dmDisplayFrequency = displayFrequency;
     dm.dmFields = DEVMODE.DM_PELSWIDTH | DEVMODE.DM_PELSHEIGHT | DEVMODE.DM_DISPLAYFREQUENCY;
     RetVal = ChangeDisplaySettings(ref   dm, CDS_TEST);
     if (RetVal == 0)
     {
         RetVal = ChangeDisplaySettings(ref dm, 0);
         ret = true;
     }
     return ret;
 }
Exemplo n.º 21
0
        /// <summary>
        /// Gets the resolution of the display device associated with the screen.
        /// </summary>
        /// <param name="screen">The Windows Forms screen object associated with the display device.</param>
        /// <returns>A struct having the screen, display device width, and display device height.</returns>
        public static DeviceResolution GetDeviceResolution(System.Windows.Forms.Screen screen)
        {
            DEVMODE dm = new DEVMODE
            {
                dmSize = (short)Marshal.SizeOf(typeof(DEVMODE))
            };

            EnumDisplaySettings(screen.DeviceName, ENUM_CURRENT_SETTINGS, ref dm);

            DeviceResolution deviceResolution = new DeviceResolution()
            {
                screen = screen,
                width  = dm.dmPelsWidth,
                height = dm.dmPelsHeight
            };

            return(deviceResolution);
        }
Exemplo n.º 22
0
        static void Main()
        {
            DEVMODE mode = new DEVMODE();

            mode = DEVMODE.UI;

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            if (mode == DEVMODE.UI)
            {
                Application.Run(new FlashPanel());
            }
            else if (mode == DEVMODE.DEVICE)
            {
                Application.Run(new Form1());
            }
        }
Exemplo n.º 23
0
        /// <summary>
        ///     Getter for user resolutions.
        ///     Called by Program upon application start.
        /// </summary>
        public void getResolutions()
        {
            List <string> tempList = new List <string>();
            DEVMODE       vDevMode = new DEVMODE();
            int           i        = 0;

            while (EnumDisplaySettings(null, i, ref vDevMode))
            {
                tempList.Add(vDevMode.dmPelsWidth + "x" + vDevMode.dmPelsHeight);
                i++;
            }

            int maxLength = tempList.Max(x => x.Length);
            IOrderedEnumerable <string> orderedList = tempList.OrderBy(x => x.PadLeft(maxLength, '0'));

            ResolutionList = orderedList.Distinct().ToList();
            logger.Debug("getResolutions - found a total of {0} available resolutions.", ResolutionList.Count);
        }
Exemplo n.º 24
0
        static void Main(string[] args)
        {
            DEVMODE vDevMode = new DEVMODE();
            int     i        = 0;

            while (EnumDisplaySettings(null, i, ref vDevMode))
            {
                if (vDevMode.dmPelsWidth > 1080 && (1 << vDevMode.dmBitsPerPel) > 256)
                {
                    Console.WriteLine("Width:{0} Height:{1} Color:{2} Frequency:{3}",
                                      vDevMode.dmPelsWidth,
                                      vDevMode.dmPelsHeight,
                                      1 << vDevMode.dmBitsPerPel,
                                      vDevMode.dmDisplayFrequency);
                }
                i++;
            }
        }
Exemplo n.º 25
0
        public void FindValidDisplayModes()
        {
            int dMode = -1;

            AvailScrRes = new List <DEVMODE>();

            DEVMODE DM = new DEVMODE();

            DM.dmSize   = (short)Marshal.SizeOf(DM);
            DM.dmFields = (int)(DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL);
            while (User32.EnumDisplaySettings(null, dMode, ref DM) > 0)
            {
                AvailScrRes.Add(DM);
                dMode++;
            }

            piAvailableDisplayModes = AvailScrRes.Count;
        }
Exemplo n.º 26
0
        private Rectangle GetGameWindowBounds(HandleRef windowHandle)
        {
            Rectangle result       = GetGameWindowBoundsRaw(windowHandle);
            Screen    activeScreen = Screen.FromHandle(windowHandle.Handle);

            if (result.Width > 0 && PlayerSettingsDB.Get().useFullScreenCapture)
            {
                result       = Screen.GetBounds(result);
                activeScreen = Screen.FromRectangle(result);
            }

            if (activeScreen != cachedScreen)
            {
                cachedScreen = activeScreen;

                DEVMODE dm = new DEVMODE();
                dm.dmSize = (short)Marshal.SizeOf(typeof(DEVMODE));
                EnumDisplaySettings(cachedScreen.DeviceName, -1, ref dm);

                if (dm.dmPelsWidth == cachedScreen.Bounds.Width)
                {
                    cachedScreenScaling = 1.0f;
                }
                else
                {
                    cachedScreenScaling = (float)cachedScreen.Bounds.Width / (float)dm.dmPelsWidth;
                }

                if (Logger.IsSuperVerbose())
                {
                    Logger.WriteLine("GetGameWindowBounds, caching screen data: bounds:{0}, pelsWidth:{1} => scale:{2}", cachedScreen.Bounds, dm.dmPelsWidth, cachedScreenScaling);
                }
            }

            if (cachedScreenScaling != 1.0f)
            {
                result.X      = cachedScreen.Bounds.X + (int)((result.X - cachedScreen.Bounds.X) / cachedScreenScaling);
                result.Y      = cachedScreen.Bounds.Y + (int)((result.Y - cachedScreen.Bounds.Y) / cachedScreenScaling);
                result.Width  = (int)(result.Width / cachedScreenScaling);
                result.Height = (int)(result.Height / cachedScreenScaling);
            }

            return(result);
        }
Exemplo n.º 27
0
        public void InsertDefaultValues()
        {
            //Insert resolutions
            DEVMODE vDevMode = new DEVMODE();
            int i = 0;

            while (EnumDisplaySettings(null, i, ref vDevMode))
            {
                if (!Resolutions.Contains(String.Format("{0}x{1}", vDevMode.dmPelsWidth, vDevMode.dmPelsHeight)) && vDevMode.dmPelsWidth >= 1000)
                {
                    Resolutions.Add(String.Format("{0}x{1}", vDevMode.dmPelsWidth, vDevMode.dmPelsHeight));
                    ResolutionComboBox.Items.Add(String.Format("{0}x{1}", vDevMode.dmPelsWidth, vDevMode.dmPelsHeight));
                }
                i++;
            }

            ResolutionComboBox.SelectedIndex = ResolutionComboBox.Items.Count - 1;
            WindowModeComboBox.SelectedIndex = 0;
        }
Exemplo n.º 28
0
            public static List <DEVMODE> GetScreenInfo(string devicename = null)
            {
                DEVMODE        vDevMode = new DEVMODE();
                List <DEVMODE> info     = new List <DEVMODE>();

                int i = 0;

                while (EnumDisplaySettings(devicename, i, ref vDevMode))
                {
                    if (!Contains(info, vDevMode.dmPelsWidth, vDevMode.dmPelsHeight))
                    {
                        AddSorted(info, vDevMode);
                    }

                    i++;
                }

                return(info);
            }
Exemplo n.º 29
0
        public void InsertDefaultValues()
        {
            //Insert resolutions
            DEVMODE vDevMode = new DEVMODE();
            int     i        = 0;

            while (EnumDisplaySettings(null, i, ref vDevMode))
            {
                if (!Resolutions.Contains(String.Format("{0}x{1}", vDevMode.dmPelsWidth, vDevMode.dmPelsHeight)) && vDevMode.dmPelsWidth >= 1000)
                {
                    Resolutions.Add(String.Format("{0}x{1}", vDevMode.dmPelsWidth, vDevMode.dmPelsHeight));
                    ResolutionComboBox.Items.Add(String.Format("{0}x{1}", vDevMode.dmPelsWidth, vDevMode.dmPelsHeight));
                }
                i++;
            }

            ResolutionComboBox.SelectedIndex = ResolutionComboBox.Items.Count - 1;
            WindowModeComboBox.SelectedIndex = 0;
        }
Exemplo n.º 30
0
        //设置分辨率,width宽,height高,displayFrequency刷新频率,设置成功返回true,否则false
        //调用方式: setResolution(1024, 768, 75);
        public bool setResolution(int width, int height, int displayFrequency)
        {
            bool    ret    = false;
            long    RetVal = 0;
            DEVMODE dm     = new DEVMODE();

            dm.dmSize             = (short)Marshal.SizeOf(typeof(DEVMODE));
            dm.dmPelsWidth        = width;
            dm.dmPelsHeight       = height;
            dm.dmDisplayFrequency = displayFrequency;
            dm.dmFields           = DEVMODE.DM_PELSWIDTH | DEVMODE.DM_PELSHEIGHT | DEVMODE.DM_DISPLAYFREQUENCY;
            RetVal = ChangeDisplaySettings(ref dm, CDS_TEST);
            if (RetVal == 0)
            {
                RetVal = ChangeDisplaySettings(ref dm, 0);
                ret    = true;
            }
            return(ret);
        }
Exemplo n.º 31
0
        private int FindDevModeMatchingXY(int x, int y)
        {
            listSettings.Clear();

            string  devName = GetDeviceName(0);
            DEVMODE devMode = new DEVMODE();
            int     modeNum = 0;
            bool    result  = true;

            do
            {
                result = EnumDisplaySettings(devName, modeNum, ref devMode);

                if (result)
                {
                    string item = DevmodeToString(devMode);
                    listSettings.Add(item);
                }
                modeNum++;
            } while (result);

            if (listSettings.Count > 0)
            {
                for (int n = 0; n < modeNum; n++)
                {
                    DEVMODE modeinfo = GetDevmode(0, n);
                    if (modeinfo.dmPelsWidth == x && modeinfo.dmPelsHeight == y && modeinfo.dmDisplayFrequency == 29 && modeinfo.dmBitsPerPel == 8)
                    {
                        return(n);
                    }
                }

                //int selected = listSettings.IndexOf(DevmodeToString(current));
                //if (selected >= 0)
                //{
                //    currentDevMode = current;
                //    //listSettings.SelectedIndex = selected;
                //    ////   listSettings.SetSelected(selected, true);
                //}
            }

            return(0);
        }
Exemplo n.º 32
0
        public static void ChangeDisplaySettings(int width, int height, int frequency, int orientation)
        {
            DEVMODE originalMode = new DEVMODE();

            originalMode.dmSize =
                (ushort)Marshal.SizeOf(originalMode);

            // Retrieving current settings
            // to edit them
            EnumDisplaySettings(null,
                                -1,
                                ref originalMode);

            // Making a copy of the current settings
            // to allow reseting to the original mode
            DEVMODE newMode = originalMode;

            // Changing the settings
            newMode.dmPelsWidth          = (uint)width;
            newMode.dmPelsHeight         = (uint)height;
            newMode.dmDisplayFrequency   = (uint)frequency;
            newMode.dmDisplayOrientation = (uint)orientation;

            // Capturing the operation result
            int result = ChangeDisplaySettings(ref newMode, 0);

            if (result == 0)
            {
                Console.WriteLine("Succeeded.");
            }
            else if (result == -2)
            {
                Console.WriteLine("Mode not supported.");
            }
            else if (result == 1)
            {
                Console.WriteLine("Restart required.");
            }
            else
            {
                Console.WriteLine("Failed. Error code = {0}", result);
            }
        }
Exemplo n.º 33
0
 static void Main(string[] args)
 {
     DEVMODE vDevMode = new DEVMODE();
     int i = 0;
     while (EnumDisplaySettings(null, i, ref vDevMode))
     {
         //filters out important resolutions
         if (vDevMode.dmDisplayFrequency == 60 && (1 << vDevMode.dmBitsPerPel) == 65536)
         {
             Console.WriteLine("Width:{0} Height:{1} Color:{2} Frequency:{3}",
                                     vDevMode.dmPelsWidth,
                                     vDevMode.dmPelsHeight,
                                     1 << vDevMode.dmBitsPerPel, vDevMode.dmDisplayFrequency
                                 );
         }
         i++;
     }
     Console.ReadLine();
 }
Exemplo n.º 34
0
        /// <summary>
        /// Returns the current frequency of the integrated display.
        /// </summary>
        /// <returns></returns>
        public uint?GetIntegratedDisplayFrequency()
        {
            string devName = this.GetIntegratedDisplayName();

            if (devName == null)
            {
                return(null);
            }

            DEVMODE current = default;

            current.dmSize = (ushort)Marshal.SizeOf <DEVMODE>();
            if (!User32.EnumDisplaySettings(devName, User32.ENUM_CURRENT_SETTINGS, ref current))
            {
                return(null);
            }

            return(current.dmDisplayFrequency);
        }
Exemplo n.º 35
0
    public static void SetAsPrimaryMonitor(uint id)
    {
        var device     = new DISPLAY_DEVICE();
        var deviceMode = new DEVMODE();

        device.cb = Marshal.SizeOf(device);
        NativeMethods.EnumDisplayDevices(null, id, ref device, 0);
        NativeMethods.EnumDisplaySettings(device.DeviceName, -1, ref deviceMode);
        var offsetx = deviceMode.dmPosition.x;
        var offsety = deviceMode.dmPosition.y;

        deviceMode.dmPosition.x = 0;
        deviceMode.dmPosition.y = 0;
        NativeMethods.ChangeDisplaySettingsEx(
            device.DeviceName,
            ref deviceMode,
            (IntPtr)null,
            (ChangeDisplaySettingsFlags.CDS_SET_PRIMARY | ChangeDisplaySettingsFlags.CDS_UPDATEREGISTRY | ChangeDisplaySettingsFlags.CDS_NORESET),
            IntPtr.Zero);
        device    = new DISPLAY_DEVICE();
        device.cb = Marshal.SizeOf(device);
        // Update remaining devices
        for (uint otherid = 0; NativeMethods.EnumDisplayDevices(null, otherid, ref device, 0); otherid++)
        {
            if (device.StateFlags.HasFlag(DisplayDeviceStateFlags.AttachedToDesktop) && otherid != id)
            {
                device.cb = Marshal.SizeOf(device);
                var otherDeviceMode = new DEVMODE();
                NativeMethods.EnumDisplaySettings(device.DeviceName, -1, ref otherDeviceMode);
                otherDeviceMode.dmPosition.x -= offsetx;
                otherDeviceMode.dmPosition.y -= offsety;
                NativeMethods.ChangeDisplaySettingsEx(
                    device.DeviceName,
                    ref otherDeviceMode,
                    (IntPtr)null,
                    (ChangeDisplaySettingsFlags.CDS_UPDATEREGISTRY | ChangeDisplaySettingsFlags.CDS_NORESET),
                    IntPtr.Zero);
            }
            device.cb = Marshal.SizeOf(device);
        }
        // Apply settings
        NativeMethods.ChangeDisplaySettingsEx(null, IntPtr.Zero, (IntPtr)null, ChangeDisplaySettingsFlags.CDS_NONE, (IntPtr)null);
    }
Exemplo n.º 36
0
        private void PopulateResSelector()
        {
            DEVMODE vDevMode = new DEVMODE();
            int     i        = 0;

            while (EnumDisplaySettings(null, i, ref vDevMode))
            {
                if (!comboBoxResWidth.Items.Contains(vDevMode.dmPelsWidth))
                {
                    comboBoxResWidth.Items.Add(vDevMode.dmPelsWidth);
                }
                if (!comboBoxResHeight.Items.Contains(vDevMode.dmPelsHeight))
                {
                    comboBoxResHeight.Items.Add(vDevMode.dmPelsHeight);
                }

                i++;
            }
        }
Exemplo n.º 37
0
        private string ChangeMainDisplayPosition(string name, int x, int y)
        {
            DEVMODE dm = GetDEVMODE();

            //if (0 != Native.Methods.EnumDisplaySettings(@"\\.\DISPLAY1", Native.Methods.ENUM_CURRENT_SETTINGS, ref dm))
            if (0 != Native.Methods.EnumDisplaySettings(name, Native.Methods.ENUM_CURRENT_SETTINGS, ref dm))
            {
                dm.dmPositionX = x;
                dm.dmPositionY = y;

                DisplayChangeResult iRet = Native.Methods.ChangeDisplaySettings(ref dm, ChangeDisplaySettingsFlags.CDS_TEST);
                if (iRet == DisplayChangeResult.Failed)
                {
                    return("Unable To Process Your Request. Sorry For This Inconvenience.");
                }
                else
                {
                    iRet = Native.Methods.ChangeDisplaySettings(ref dm, 0);
                    switch (iRet)
                    {
                    case DisplayChangeResult.Successful:
                    {
                        return("Success");
                    }

                    case DisplayChangeResult.Restart:
                    {
                        return("You Need To Reboot For The Change To Happen.\n If You Feel Any Problem After Rebooting Your Machine\nThen Try To Change Resolution In Safe Mode.");
                    }

                    default:
                    {
                        return("Failed To Change The Position");
                    }
                    }
                }
            }
            else
            {
                return("Failed To Change The Position.");
            }
        }
Exemplo n.º 38
0
        static void Main(string[] args)
        {
            for (;;)
            {
                for (uint i = 0;; ++i)
                {
                    DISPLAY_DEVICE dev = default;
                    dev.cb = Marshal.SizeOf <DISPLAY_DEVICE>();
                    if (!User32.EnumDisplayDevices(null, i, ref dev, 0))
                    {
                        break;
                    }

                    if ((dev.StateFlags & DisplayDeviceStateFlags.AttachedToDesktop) == 0)
                    {
                        continue;
                    }

                    Console.WriteLine(dev.DeviceID);
                    Console.WriteLine(dev.DeviceKey);
                    Console.WriteLine(dev.DeviceName);
                    Console.WriteLine(dev.DeviceString);
                    Console.WriteLine(dev.StateFlags);
                    Console.WriteLine();

                    for (int j = -1;; ++j)
                    {
                        DEVMODE mode = default;
                        mode.dmSize = (ushort)Marshal.SizeOf <DEVMODE>();
                        if (!User32.EnumDisplaySettings(dev.DeviceName, j, ref mode))
                        {
                            break;
                        }

                        Console.WriteLine($"{mode.dmDeviceName} {mode.dmPosition.x},{mode.dmPosition.y} {mode.dmFormName} {mode.dmPelsWidth}x{mode.dmPelsHeight}x{mode.dmBitsPerPel} {mode.dmDisplayFrequency}");
                    }
                }

                Console.WriteLine("-----");
                Console.ReadKey();
            }
        }
        public ReturnValues ChangeSettings(DEVMODE devmode, out string err)
        {
            err = null;

            ReturnValues iRet = (ReturnValues)ChangeDisplaySettings(ref devmode, 0);

            switch (iRet)
            {
            case Win32.ReturnValues.DISP_CHANGE_SUCCESSFUL:
                err = Win32.ReturnValueText.DISP_CHANGE_SUCCESSFUL;
                break;

            case Win32.ReturnValues.DISP_CHANGE_RESTART:
                err = Win32.ReturnValueText.DISP_CHANGE_RESTART;
                break;

            case Win32.ReturnValues.DISP_CHANGE_FAILED:
                err = Win32.ReturnValueText.DISP_CHANGE_FAILED;
                break;

            case Win32.ReturnValues.DISP_CHANGE_BADDUALVIEW:
                err = Win32.ReturnValueText.DISP_CHANGE_BADDUALVIEW;
                break;

            case Win32.ReturnValues.DISP_CHANGE_BADFLAGS:
                err = Win32.ReturnValueText.DISP_CHANGE_BADFLAGS;
                break;

            case Win32.ReturnValues.DISP_CHANGE_BADPARAM:
                err = Win32.ReturnValueText.DISP_CHANGE_BADPARAM;
                break;

            case Win32.ReturnValues.DISP_CHANGE_NOTUPDATED:
                err = Win32.ReturnValueText.DISP_CHANGE_NOTUPDATED;
                break;

            default:
                err = Win32.ReturnValueText.DISP_CHANGE_OTHER;
                break;
            }
            return(iRet);
        }
            public static int ChangeResolution(int width, int height)
            {
                DEVMODE dm = GetDevMode1();

                if (User_32.EnumDisplaySettings(null, User_32.ENUM_CURRENT_SETTINGS, ref dm))
                {
                    dm.dmPelsWidth  = width;
                    dm.dmPelsHeight = height;

                    int iRet = User_32.ChangeDisplaySettings(ref dm, User_32.CDS_TEST);

                    if (iRet == User_32.DISP_CHANGE_FAILED)
                    {
                        return(-1);
                    }
                    else
                    {
                        iRet = User_32.ChangeDisplaySettings(ref dm, User_32.CDS_UPDATEREGISTRY);
                        switch (iRet)
                        {
                        case User_32.DISP_CHANGE_SUCCESSFUL:
                        {
                            return(0);
                        }

                        case User_32.DISP_CHANGE_RESTART:
                        {
                            return(1);
                        }

                        default:
                        {
                            return(-1);
                        }
                        }
                    }
                }
                else
                {
                    return(-1);
                }
            }
Exemplo n.º 41
0
        public GetResolution()
        {
            DEVMODE DevMode = new DEVMODE();
            List<string> resList = new List<string>();
            resolutions = new List<string>();

            int i = 0;
            while (EnumDisplaySettings(null, i, ref DevMode))
            {
                string res = (DevMode.dmPelsWidth < 1000 ? "  " + DevMode.dmPelsWidth.ToString() : DevMode.dmPelsWidth.ToString()) + " x" +
                             (DevMode.dmPelsHeight < 1000 ? " " + DevMode.dmPelsHeight.ToString() : DevMode.dmPelsHeight.ToString());
                if (!resList.Exists(x => x == res))
                {
                    resList.Add(res);
                }
                i++;
            }

            resolutions = resList.OrderByDescending(x => x).ToList();
        }
Exemplo n.º 42
0
        /// <summary>
        /// Changing the settings
        /// </summary>
        public void Apply()
        {
            originalMode.dmSize = (short)Marshal.SizeOf(originalMode);

            // Retrieving current settings
            // to edit them
            EnumDisplaySettings(null, ENUM_CURRENT_SETTINGS, ref originalMode);

            // Making a copy of the current settings
            // to allow reseting to the original mode
            DEVMODE newMode = originalMode;

            // Changing the settings
            newMode.dmPelsWidth        = Width;
            newMode.dmPelsHeight       = Height;
            newMode.dmBitsPerPel       = BitsPerPel;
            newMode.dmDisplayFrequency = DisplayFrequency;

            changed = ChangeDisplaySettings(ref newMode, 0) == DISP_CHANGE_SUCCESSFUL;
        }
Exemplo n.º 43
0
        static void Main(string[] args)
        {
            DEVMODE vDevMode = new DEVMODE();
            int     i        = 0;

            while (EnumDisplaySettings(null, i, ref vDevMode))
            {
                //filters out important resolutions
                if (vDevMode.dmDisplayFrequency == 60 && (1 << vDevMode.dmBitsPerPel) == 65536)
                {
                    Console.WriteLine("Width:{0} Height:{1} Color:{2} Frequency:{3}",
                                      vDevMode.dmPelsWidth,
                                      vDevMode.dmPelsHeight,
                                      1 << vDevMode.dmBitsPerPel, vDevMode.dmDisplayFrequency
                                      );
                }
                i++;
            }
            Console.ReadLine();
        }
Exemplo n.º 44
0
        //====================================================================================================================

        #region Dekstop Screen Capture

        public static Bitmap Screenshot(Screen screen)
        {
            DEVMODE dm = new DEVMODE();

            dm.dmSize = (short)Marshal.SizeOf(typeof(DEVMODE));
            EnumDisplaySettings(screen.DeviceName, ENUM_CURRENT_SETTINGS, ref dm);

            Bitmap screenshot;

            using (Bitmap bmp = new Bitmap(dm.dmPelsWidth, dm.dmPelsHeight))
                using (Graphics g = Graphics.FromImage(bmp))
                {
                    g.CopyFromScreen(dm.dmPositionX, dm.dmPositionY, 0, 0, bmp.Size);
                    screenshot = new Bitmap(bmp, 1024, 768);
                    //bmp.Save(screen.DeviceName.Split('\\').Last() + ".png");
                }


            return(screenshot);
        }
Exemplo n.º 45
0
        /// <summary>
        /// Get all available graphics modes
        /// </summary>
        /// <param name="displayCompatableOnly">Use all modes that the adapter can produce (but the attached display might not support)</param>
        /// <returns>An array of available graphics modes</returns>
        protected graphicsMode[] enumerateModes(bool displayCompatableOnly)
        {
            int       i       = 0;
            DEVMODE   devmode = initNewDEVMODE();
            ArrayList modes   = new ArrayList();

            while (EnumDisplaySettingsEx(this.DeviceName, i, ref devmode, displayCompatableOnly ? 0 : EDS_RAWMODE))
            {
                i++;
                modes.Add(graphicsMode.fromDevMode(devmode));
            }

            graphicsMode[] finalModes = new graphicsMode[modes.Count];
            for (i = 0; i < finalModes.Length; i++)
            {
                finalModes[i] = (graphicsMode)modes[i];
            }

            return(finalModes);
        }
Exemplo n.º 46
0
        public static List <string> Resolutions()
        {
            List <string> list     = new List <string>();
            DEVMODE       vDevMode = new DEVMODE();
            int           i        = 0;

            try
            {
                while (EnumDisplaySettings(null, i, ref vDevMode))
                {
                    list.Add(vDevMode.dmPelsWidth.ToString() + "/" + vDevMode.dmPelsHeight.ToString());
                    i++;
                }
            }
            catch
            {
                list.Clear();
            }
            return(list);
        }
        public static List <Size> GetDisplayResolutions(this Screen screen)
        {
            List <Size> sizes    = new List <Size>();
            DEVMODE     vDevMode = new DEVMODE();
            int         i        = 0;

            while (EnumDisplaySettings(screen.DeviceName, i, ref vDevMode))
            {
                if (IsReasonableDisplayResolution(vDevMode) && SupportsNormalColour(vDevMode))
                {
                    Size newsize = new Size(vDevMode.dmPelsWidth, vDevMode.dmPelsHeight);
                    if (!sizes.Contains(newsize))
                    {
                        sizes.Add(newsize);
                    }
                }
                i++;
            }

            return(sizes);
        }
Exemplo n.º 48
0
        public static void GetCurrentSettings()
        {
            DEVMODE mode = new DEVMODE();

            mode.dmSize = (ushort)Marshal.SizeOf(mode);

            if (EnumDisplaySettings(null, -1, ref mode) == true)
            {
                Console.WriteLine("Device Name:{0}\n이거 나오냐? : {1}", mode.dmDeviceName, mode.dmLogPixels);
                Console.WriteLine("Current Mode:\n\t" +
                                  "{0} by {1}, " +
                                  "{2} bit, " +
                                  "{3} degrees, " +
                                  "{4} hertz",
                                  mode.dmPelsWidth,
                                  mode.dmPelsHeight,
                                  mode.dmBitsPerPel,
                                  mode.dmDisplayOrientation * 90,
                                  mode.dmDisplayFrequency);
            }
        }
Exemplo n.º 49
0
        // take screen picture
        public string ScreenCapture()
        {
            foreach (Screen screen in Screen.AllScreens)
            {
                DEVMODE dm = new DEVMODE();
                dm.dmSize = (short)Marshal.SizeOf(typeof(DEVMODE));
                EnumDisplaySettings(screen.DeviceName, ENUM_CURRENT_SETTINGS, ref dm);

                using (Bitmap bmp = new Bitmap(dm.dmPelsWidth, dm.dmPelsHeight))
                    using (Graphics g = Graphics.FromImage(bmp))
                    {
                        g.CopyFromScreen(dm.dmPositionX, dm.dmPositionY, 0, 0, bmp.Size);
                        Console.WriteLine(screen.DeviceName.Split('\\').Last() + ".jpeg");

                        //bmp.Save(screen.DeviceName.Split('\\').Last() + ".jpeg");

                        String projectDirectory = Environment.CurrentDirectory;
                        string filepath         = Directory.GetParent(projectDirectory).Parent.FullName;

                        String[] paths = new string[] { @filepath, "files" };
                        filepath = Path.Combine(paths);

                        if (!Directory.Exists(filepath))
                        {
                            Directory.CreateDirectory(filepath);
                        }
                        string s = DateTime.Now.Day.ToString() + "-" + DateTime.Now.Month.ToString() + "-" + DateTime.Now.Year.ToString() + "_" + DateTime.Now.Hour.ToString() + "-" + DateTime.Now.Minute.ToString() + "-" + DateTime.Now.Second.ToString() + ".jpg";
                        paths    = new string[] { @filepath, s };
                        filepath = Path.Combine(paths);

                        if (!File.Exists(filepath))
                        {
                            bmp.Save(filepath);
                        }

                        return(s);
                    }
            }
            return("");
        }
        public List<DEVMODE> GetDeviceModes()
        {
            if (_resCombo == null)
            {
                _resCombo = new List<DEVMODE>();
                int i = 0;

                DEVMODE dm = new DEVMODE();
                dm.dmDeviceName = new String(new char[32]);
                dm.dmFormName = new String(new char[32]);
                dm.dmSize = (short)Marshal.SizeOf(dm);

                while (0 != NativeMethods.EnumDisplaySettings(null, i, ref dm))
                {
                    if (dm.dmBitsPerPel == 32)
                    {
                        _resCombo.Add(dm);
                    }
                    i++;
                }
            }

            return _resCombo;
        }
Exemplo n.º 51
0
 private static DEVMODE GetDevmode(int devNum, int modeNum)
 {
     //populates DEVMODE for the specified device and mode
       DEVMODE devMode = new DEVMODE();
       string devName = GetDeviceName(devNum);
       EnumDisplaySettings(devName, modeNum, ref devMode);
       return devMode;
 }
Exemplo n.º 52
0
 private static extern int ChangeDisplaySettingsEx(string lpszDeviceName, ref DEVMODE lpDevMode, IntPtr hwnd, int dwflags, IntPtr lParam);
Exemplo n.º 53
0
 private static extern bool EnumDisplaySettings(string deviceName, int modeNum, ref DEVMODE devMode);
Exemplo n.º 54
0
 public static extern int EnumDisplaySettings(string deviceName, int modeNum, ref DEVMODE devMode);
Exemplo n.º 55
0
 public static extern int ChangeDisplaySettings(ref DEVMODE devMode, int flags);
Exemplo n.º 56
0
        /// <summary>
        /// Sets the orientation of the primary screen
        /// </summary>
        /// <param name="orientation">The desired orientation</param>
        /// <returns>
        /// The result of setting the orientation:
        ///   0: Success or no change required
        ///   1: A device restart is required
        ///   -2: The device does not support this orientation
        ///   Any other number: Unknown error 
        /// </returns>
        public static int SetOrientation(DisplayOrientation orientation)
        {
            var currentSettings = new DEVMODE();
            currentSettings.dmSize = (ushort)Marshal.SizeOf(currentSettings);

            EnumDisplaySettings(null, CURRENT_SETTINGS_MODE, ref currentSettings);

            if (currentSettings.dmDisplayOrientation == (int)orientation)
            {
                return 0;
            }

            var newSettings = currentSettings;

            newSettings.dmDisplayOrientation = (uint)orientation;

            var bigDimension = Math.Max(newSettings.dmPelsHeight, newSettings.dmPelsWidth);
            var smallDimension = Math.Min(newSettings.dmPelsHeight, newSettings.dmPelsWidth);

            if (orientation == DisplayOrientation.LANDSCAPE)
            {
                newSettings.dmPelsHeight = smallDimension;
                newSettings.dmPelsWidth = bigDimension;
            }
            else
            {
                newSettings.dmPelsHeight = bigDimension;
                newSettings.dmPelsWidth = smallDimension;
            }

            return ChangeDisplaySettings(ref newSettings, 0);
        }
Exemplo n.º 57
0
 static extern bool EnumDisplaySettings(string lpszDeviceName, Int32 iModeNum, ref   DEVMODE lpDevMode);
Exemplo n.º 58
0
        private static void EnumModes(int devNum)
        {
            Settings = new List<DEVMODE>();
              string devName = GetDeviceName(devNum);
              DEVMODE devMode = new DEVMODE();

              int modeNum = 0;
              while (EnumDisplaySettings(devName, modeNum, ref devMode))
              {
            Settings.Add(devMode);
            modeNum++;
              }
        }
Exemplo n.º 59
0
        /// <summary>
        /// Gets the current orientation of the primary screen
        /// </summary>
        /// <returns>The orientation of the primary screen</returns>
        public static DisplayOrientation GetCurrentOrientation()
        {
            var currentSettings = new DEVMODE();
            currentSettings.dmSize = (ushort)Marshal.SizeOf(currentSettings);

            EnumDisplaySettings(null, CURRENT_SETTINGS_MODE, ref currentSettings);

            return (DisplayOrientation)currentSettings.dmDisplayOrientation;
        }
Exemplo n.º 60
0
 public static extern bool EnumDisplaySettingsEx(string lpszDeviceName, uint iModeNum,
                                                 ref DEVMODE lpDevMode, uint dwFlags);