Пример #1
0
        public DEVMODE1 getCurrentResolution()
        {
            DEVMODE1 dm = new DEVMODE1();

            dm.dmDeviceName = new String(new char[32]);
            dm.dmFormName   = new String(new char[32]);
            dm.dmSize       = (short)Marshal.SizeOf(dm);
            if (0 != User_32.EnumDisplaySettings(null, User_32.ENUM_CURRENT_SETTINGS, ref dm))
            {
                Console.WriteLine("\t" +
                                  "{0} by {1}, " +
                                  "{2} bit, " +
                                  "{3} degrees, " +
                                  "{4} hertz",
                                  dm.dmPelsWidth,
                                  dm.dmPelsHeight,
                                  dm.dmBitsPerPel,
                                  dm.dmDisplayOrientation * 90,
                                  dm.dmDisplayFrequency);
            }
            else
            {
                Console.WriteLine("Unable to process your request");
            }
            return(dm);
        }
Пример #2
0
        public DEVMODE1 getMaximumSupportedResolution()
        {
            DEVMODE1 dm = new DEVMODE1();

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

            int i = 0;

            while (0 != User_32.EnumDisplaySettings(null, i++, ref dm))
            {
                ;
            }

            Console.WriteLine("\t" +
                              "{0} by {1}, " +
                              "{2} bit, " +
                              "{3} degrees, " +
                              "{4} hertz," +
                              "{5} color",
                              dm.dmPelsWidth,
                              dm.dmPelsHeight,
                              dm.dmBitsPerPel,
                              dm.dmDisplayOrientation * 90,
                              dm.dmDisplayFrequency,
                              dm.dmYResolution);

            return(dm);
        }
Пример #3
0
        // Return a list of all 32-bit display resolutions supported by the CURRENT display.
        static public List <DisplayResolution> Get32BitModes()
        {
            List <DisplayResolution> result = new List <DisplayResolution>();

            DEVMODE1 dm = new DEVMODE1();

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

            // let's look at all the available modes of the given device, starting at zero
            int iModeNum = 0;
            // we're stripping out redundant modes (i.e. 640 x 480 60hz, 640 x 480 72hz)
            int lastX = 0, lastY = 0;

            while (0 != User_32.EnumDisplaySettings(null, iModeNum++, ref dm))
            {
                int curX = dm.dmPelsWidth;
                int curY = dm.dmPelsHeight;
                // modes are sorted first by pixel depth. within those groups they're sorted by resolution.
                if (dm.dmBitsPerPel == 32)
                {
                    if (curX != lastX || curY != lastY)
                    {
                        result.Add(new DisplayResolution(curX, curY));

                        lastX = curX;
                        lastY = curY;
                    }
                } // if
            }     // while

            return(result);
        } // Get32BitModes
Пример #4
0
        public CResolution(int a, int b)
        {
            Screen screen = Screen.PrimaryScreen;


            int iWidth  = a;
            int iHeight = b;


            DEVMODE1 dm = new DEVMODE1();

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

            getMaximumSupportedResolution();

            if (0 != User_32.EnumDisplaySettings(null, User_32.ENUM_CURRENT_SETTINGS, ref dm))
            {
                dm.dmPelsWidth  = iWidth;
                dm.dmPelsHeight = iHeight;

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

                if (iRet == User_32.DISP_CHANGE_FAILED)
                {
                    Console.WriteLine("Unable to process your request");
                    Console.WriteLine("Description: Unable To Process Your Request. Sorry For This Inconvenience.");
                }
                else
                {
                    iRet = User_32.ChangeDisplaySettings(ref dm, User_32.CDS_UPDATEREGISTRY);

                    switch (iRet)
                    {
                    case User_32.DISP_CHANGE_SUCCESSFUL:
                    {
                        break;

                        //successfull change
                    }

                    case User_32.DISP_CHANGE_RESTART:
                    {
                        Console.WriteLine("Description: 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.");
                        break;
                        //windows 9x series you have to restart
                    }

                    default:
                    {
                        Console.WriteLine("Description: Failed To Change The Resolution.");
                        break;
                        //failed to change
                    }
                    }
                }
            }
        }
Пример #5
0
            public SECResolution(int a, int b)
            {
                Screen screen;

                screen = (Screen)Screen.AllScreens.GetValue(1);  ////????????
                string name = screen.DeviceName;



                int iWidth  = a;
                int iHeight = b;


                DEVMODE1 dm = new DEVMODE1();

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

                if (0 != User_32.EnumDisplaySettings(name, User_32.ENUM_CURRENT_SETTINGS, ref dm))
                {
                    dm.dmPelsWidth  = iWidth;
                    dm.dmPelsHeight = iHeight;

                    // int iRet = User_32.ChangeDisplaySettings(ref dm, User_32.CDS_TEST);
                    int iRet = User_32.ChangeDisplaySettingsEx(name, ref dm, IntPtr.Zero, User_32.CDS_TEST, IntPtr.Zero);

                    if (iRet == User_32.DISP_CHANGE_FAILED)
                    {
                        MessageBox.Show("Unable to process your request");
                        MessageBox.Show("Description: Unable To Process Your Request. Sorry For This Inconvenience.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        //  iRet = User_32.ChangeDisplaySettings(ref dm, User_32.CDS_UPDATEREGISTRY);
                        iRet = User_32.ChangeDisplaySettingsEx(name, ref dm, IntPtr.Zero, User_32.CDS_UPDATEREGISTRY, IntPtr.Zero);
                        switch (iRet)
                        {
                        case User_32.DISP_CHANGE_SUCCESSFUL:
                        {
                            break;
                        }

                        case User_32.DISP_CHANGE_RESTART:
                        {
                            MessageBox.Show("Description: 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.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            break;
                        }

                        default:
                        {
                            MessageBox.Show("Description: Failed To Change The Resolution (2).", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            break;
                        }
                        }
                    }
                }
            }
Пример #6
0
        public static void Set(Size resolution)
        {
            Screen screen = Screen.PrimaryScreen;

            int iWidth = resolution.Width;
            int iHeight = resolution.Height;

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

            if (0 != User_32.EnumDisplaySettings(null, User_32.ENUM_CURRENT_SETTINGS, ref dm))
            {

                dm.dmPelsWidth = iWidth;
                dm.dmPelsHeight = iHeight;

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

                if (iRet == User_32.DISP_CHANGE_FAILED)
                {
                    MessageBox.Show("Unable to process your request");
                    MessageBox.Show("Description: Unable To Process Your Request. Sorry For This Inconvenience.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    iRet = User_32.ChangeDisplaySettings(ref dm, User_32.CDS_UPDATEREGISTRY);

                    switch (iRet)
                    {
                        case User_32.DISP_CHANGE_SUCCESSFUL:
                            {
                                break;

                                //successfull change
                            }
                        case User_32.DISP_CHANGE_RESTART:
                            {

                                MessageBox.Show("Description: 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.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                break;
                                //windows 9x series you have to restart
                            }
                        default:
                            {

                                MessageBox.Show("Description: Failed To Change The Resolution.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                break;
                                //failed to change
                            }
                    }
                }

            }
        }
Пример #7
0
        public Resolution(int a, int b) // 클래스 생성자
        {
            Screen screen = Screen.PrimaryScreen;

            int iWidth  = a;
            int iHeight = b;

            DEVMODE1 dm = new DEVMODE1();

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

            if (0 != EnumDisplaySettings(null, ENUM_CURRENT_SETTINGS, ref dm))
            {
                dm.dmPelsWidth  = iWidth;
                dm.dmPelsHeight = iHeight;

                int iRet = ChangeDisplaySettings(ref dm, CDS_TEST);

                if (iRet == DISP_CHANGE_FAILED)
                {
                    MessageBox.Show("Unable to process your request");
                    MessageBox.Show("Description: Unable To Process Your Request. Sorry For This Inconvenience.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    iRet = ChangeDisplaySettings(ref dm, CDS_UPDATEREGISTRY);

                    switch (iRet)
                    {
                    case DISP_CHANGE_SUCCESSFUL:
                    {
                        break;

                        //successfull change
                    }

                    case DISP_CHANGE_RESTART:
                    {
                        MessageBox.Show("Description: 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.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        break;
                        //windows 9x series you have to restart
                    }

                    default:
                    {
                        MessageBox.Show("Description: Failed To Change The Resolution.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        break;
                        //failed to change
                    }
                    }
                }
            }
        }         // end of 생성자
Пример #8
0
        public List <DEVMODE1> getSupportedResolutionList()
        {
            List <DEVMODE1> ResolutionList = new List <DEVMODE1>();

            DEVMODE1 CurrentResolution = getCurrentResolution();

            DEVMODE1 dm = new DEVMODE1();

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

            int previousResolutionX = 0;
            int previousResolutionY = 0;

            int i = 0, k = 0;

            while (0 != User_32.EnumDisplaySettings(null, i++, ref dm))
            {
                if ((dm.dmPelsWidth > previousResolutionX || dm.dmPelsHeight > previousResolutionY) && dm.dmBitsPerPel >= 32)
                {
                    /*  Console.WriteLine("\t" +
                     * "{0} by {1}, " +
                     * "{2} bit, " +
                     * "{3} degrees, " +
                     * "{4} hertz," +
                     * "{5} color",
                     * dm.dmPelsWidth,
                     * dm.dmPelsHeight,
                     * dm.dmBitsPerPel,
                     * dm.dmDisplayOrientation * 90,
                     * dm.dmDisplayFrequency,
                     * dm.dmYResolution);*/
                    k++;
                    if (dm.dmPelsWidth == CurrentResolution.dmPelsWidth && dm.dmPelsHeight == CurrentResolution.dmPelsHeight && dm.dmBitsPerPel == CurrentResolution.dmBitsPerPel)
                    {
                        selectedIndexOfCurrentResolution = k;
                    }
                    ResolutionList.Add(dm);

                    previousResolutionX = dm.dmPelsWidth;
                    previousResolutionY = dm.dmPelsHeight;

                    dm = new DEVMODE1();
                    dm.dmDeviceName = new String(new char[32]);
                    dm.dmFormName   = new String(new char[32]);
                    dm.dmSize       = (short)Marshal.SizeOf(dm);
                }
            }
            return(ResolutionList);
        }
Пример #9
0
        public static void GetMaxResolutionWithRefreshRate(string deviceName, out int dispWidth, out int dispHeight, out int refreshRate)
        {
            dispWidth = dispHeight = refreshRate = 0;
            DEVMODE1 deviceMode = new DEVMODE1();

            for (int i = 0; User_32.EnumDisplaySettings(deviceName, i, ref deviceMode) != 0; i++)
            {
                if (deviceMode.dmPelsWidth > dispWidth || (deviceMode.dmPelsWidth == dispWidth && deviceMode.dmPelsHeight >= dispHeight && deviceMode.dmDisplayFrequency >= refreshRate))
                {
                    dispWidth   = deviceMode.dmPelsWidth;
                    dispHeight  = deviceMode.dmPelsHeight;
                    refreshRate = deviceMode.dmDisplayFrequency;
                }
            }
        }
Пример #10
0
        // Return the resolution of the current display device.
        // Returns null if the device was for some reason unreadable.
        static public DisplayResolution CurrentResolution()
        {
            DEVMODE1 dm = new DEVMODE1();

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

            DisplayResolution result = null;

            if (0 != User_32.EnumDisplaySettings(null, User_32.ENUM_CURRENT_SETTINGS, ref dm))
            {
                result = new DisplayResolution(dm.dmPelsWidth, dm.dmPelsHeight);
            }

            return(result);
        }
Пример #11
0
    public static bool CResolution(int iWidth, int iHeight, out DEVMODE1 devmode)
    {
        DEVMODE1 dm = new DEVMODE1();

        dm.dmDeviceName = new String(new char[32]);
        dm.dmFormName   = new String(new char[32]);
        dm.dmSize       = (short)Marshal.SizeOf(dm);
        devmode         = dm;
        if (0 != EnumDisplaySettings(null, ENUM_CURRENT_SETTINGS, ref dm))
        {
            devmode         = dm;
            dm.dmPelsWidth  = iWidth;
            dm.dmPelsHeight = iHeight;
            return(CResolution(ref dm));
        }
        return(false);
    }
Пример #12
0
        public List <DEVMODE1> getSupportedResolutionList()
        {
            List <DEVMODE1> ResolutionList = new List <DEVMODE1>();

            DEVMODE1 dm = new DEVMODE1();

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

            int previousResolutionX = 0;
            int previousResolutionY = 0;

            int i = 0;

            while (0 != User_32.EnumDisplaySettings(null, i++, ref dm))
            {
                if (dm.dmPelsWidth > previousResolutionX || dm.dmPelsHeight > previousResolutionY)
                {
                    Console.WriteLine("\t" +
                                      "{0} by {1}, " +
                                      "{2} bit, " +
                                      "{3} degrees, " +
                                      "{4} hertz," +
                                      "{5} color",
                                      dm.dmPelsWidth,
                                      dm.dmPelsHeight,
                                      dm.dmBitsPerPel,
                                      dm.dmDisplayOrientation * 90,
                                      dm.dmDisplayFrequency,
                                      dm.dmYResolution);

                    ResolutionList.Add(dm);

                    previousResolutionX = dm.dmPelsWidth;
                    previousResolutionY = dm.dmPelsHeight;

                    dm = new DEVMODE1();
                    dm.dmDeviceName = new String(new char[32]);
                    dm.dmFormName   = new String(new char[32]);
                    dm.dmSize       = (short)Marshal.SizeOf(dm);
                }
            }
            return(ResolutionList);
        }
Пример #13
0
        protected override void OnLoad(System.EventArgs e)
        {
            dm = new DEVMODE1();
            dm.dmDeviceName = new String(new char[32]);
            dm.dmFormName   = new String(new char[32]);
            dm.dmSize       = (short)Marshal.SizeOf(dm);

            int i   = 0;
            int err = 0;

            string selectedStr   = null;
            int    selectedIndex = -1;

            err = User_32.EnumDisplaySettings(null, User_32.ENUM_CURRENT_SETTINGS, ref dm);
            if (err != 0)
            {
                selectedStr = "" + dm.dmPelsWidth + "x" + dm.dmPelsHeight
                              + "x" + dm.dmBitsPerPel + "@" + dm.dmDisplayFrequency;
            }
            else
            {
                MessageBox.Show("Unable to query current video mode");
            }


            while ((err = User_32.EnumDisplaySettings(null, i, ref dm)) > 0)
            {
                string mode = "" + dm.dmPelsWidth + "x" + dm.dmPelsHeight
                              + "x" + dm.dmBitsPerPel + "@" + dm.dmDisplayFrequency;
                videoModeCombo.Items.Add(mode);
                if (selectedStr != null && mode.Equals(selectedStr))
                {
                    selectedIndex = i;
                }
                i++;
            }

            if (selectedIndex >= 0)
            {
                videoModeCombo.SelectedIndex = selectedIndex;
            }

            base.OnLoad(e);
        }
Пример #14
0
        protected override void OnLoad(System.EventArgs e)
        {
            dm = new DEVMODE1();
            dm.dmDeviceName = new String(new char[32]);
            dm.dmFormName = new String(new char[32]);
            dm.dmSize = (short)Marshal.SizeOf(dm);

            int i = 0;
            int err = 0;

            string selectedStr = null;
            int selectedIndex=-1;

            err = User_32.EnumDisplaySettings(null, User_32.ENUM_CURRENT_SETTINGS, ref dm);
            if (err != 0)
            {
                selectedStr = "" + dm.dmPelsWidth + "x" + dm.dmPelsHeight
                              + "x" + dm.dmBitsPerPel + "@" + dm.dmDisplayFrequency;

            }
            else
            {
                MessageBox.Show("Unable to query current video mode");
            }

            while ((err = User_32.EnumDisplaySettings(null, i, ref dm)) > 0)
            {
                string mode = ""+dm.dmPelsWidth+"x"+dm.dmPelsHeight
                              +"x"+dm.dmBitsPerPel+"@"+dm.dmDisplayFrequency;
                videoModeCombo.Items.Add(mode);
                if (selectedStr != null && mode.Equals(selectedStr))
                {
                    selectedIndex = i;
                }
                i++;
            }

            if (selectedIndex >= 0)
            {
                videoModeCombo.SelectedIndex = selectedIndex;
            }

            base.OnLoad(e);
        }
Пример #15
0
        public static int ChangeResolution(int Width, int Height)
        {
            Screen screen = Screen.PrimaryScreen;

            DEVMODE1 dm = new DEVMODE1();

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


            if (User_32.EnumDisplaySettings(null, User_32.ENUM_CURRENT_SETTINGS, ref dm) == 0)
            {
                return(User_32.DISP_CHANGE_FAILED);
            }


            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(iRet);
            }
            else
            {
                /*
                 * Thats good article, it gave me some initial knowledge and the direction of further searching.
                 * There is some useful tip that I have encountered while writing my own application:
                 * You can use another constant CDS_FULLSCREEN = 0x04 instead of CDS_UPDATEREGISTRY = 0x01 when changing resolution:
                 * [code] User_32.ChangeDisplaySettings(ref dm, User_32.CDS_FULLSCREEN); [/code]
                 * This gives you some benefits: resolution is changed temporally, you even do not need to restore previous settings - it is done automatically when the application exits. And, this doesn't disorder the icons - the desktop is not even affected.
                 * I used this in writing a small game that run in full screen - form was covering the whole screen (automatically covering taskbar).
                 * Maybe this information can help someone else too.
                 */
                return(User_32.ChangeDisplaySettings(ref dm, User_32.CDS_FULLSCREEN));
                //return User_32.ChangeDisplaySettings(ref dm, User_32.CDS_UPDATEREGISTRY);
            }
        }
Пример #16
0
        public void setSupportedResolution(DEVMODE1 dm)
        {
            int iRet = User_32.ChangeDisplaySettings(ref dm, User_32.CDS_TEST);

            if (iRet == User_32.DISP_CHANGE_FAILED)
            {
                Console.WriteLine("Unable to process your request");
                Console.WriteLine("Description: Unable To Process Your Request. Sorry For This Inconvenience.");
            }
            else
            {
                iRet = User_32.ChangeDisplaySettings(ref dm, User_32.CDS_UPDATEREGISTRY);

                switch (iRet)
                {
                case User_32.DISP_CHANGE_SUCCESSFUL:
                {
                    break;

                    //successfull change
                }

                case User_32.DISP_CHANGE_RESTART:
                {
                    Console.WriteLine("Description: 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.");
                    break;
                    //windows 9x series you have to restart
                }

                default:
                {
                    Console.WriteLine("Description: Failed To Change The Resolution.");
                    break;
                    //failed to change
                }
                }
            }
        }
Пример #17
0
    public static bool CResolution(ref DEVMODE1 dm)
    {
        int iRet = ChangeDisplaySettings(ref dm, CDS_TEST);

        if (iRet == DISP_CHANGE_FAILED)
        {
            MessageBox.Show("Unable to process your request");
            MessageBox.Show("Description: Unable To Process Your Request. Sorry For This Inconvenience.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
            return(false);
        }
        else
        {
            iRet = ChangeDisplaySettings(ref dm, CDS_UPDATEREGISTRY);

            switch (iRet)
            {
            case DISP_CHANGE_SUCCESSFUL:
            {
                return(true);
                //successfull change
            }

            case DISP_CHANGE_RESTART:
            {
                MessageBox.Show("Description: 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.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                //windows 9x series you have to restart
                return(false);
            }

            default:
            {
                MessageBox.Show("Description: Failed To Change The Resolution.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return(false);
                //failed to change
            }
            }
        }
    }
Пример #18
0
        public void triggerResolutionSwitch()
        {
            CResolution     res1   = new CResolution();
            DEVMODE1        dm1    = res1.getCurrentResolution();
            List <DEVMODE1> dmlist = res1.getSupportedResolutionList();

            DEVMODE1 dm2;

            int currentposition = res1.selectedIndexOfCurrentResolution;

            if (currentposition - 2 >= 0)
            {
                dm2 = dmlist[currentposition - 2];
            }
            else
            {
                dm2 = dmlist[currentposition - 1];
            }


            res1.setSupportedResolution(dm2);
            Thread.Sleep(2000);
            res1.setSupportedResolution(dm1);
        }
 public static extern int ChangeDisplaySettings(ref DEVMODE1 devMode, int flags);
 public static extern int EnumDisplaySettings(string deviceName, int modeNum, ref DEVMODE1 devMode);
Пример #21
0
 public static extern int EnumDisplaySettings(string deviceName, int modeNum, ref DEVMODE1 devMode );
Пример #22
0
 public static extern int ChangeDisplaySettings(ref DEVMODE1 devMode, int flags);
Пример #23
0
            public SECResolution(int a, int b)
            {
                Screen screen;

                screen = (Screen)Screen.AllScreens.GetValue(1);  ////????????
                string name = screen.DeviceName;

                int iWidth = a;
                int iHeight = b;

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

                if (0 != User_32.EnumDisplaySettings(name, User_32.ENUM_CURRENT_SETTINGS, ref dm))
                {

                    dm.dmPelsWidth = iWidth;
                    dm.dmPelsHeight = iHeight;

                    // int iRet = User_32.ChangeDisplaySettings(ref dm, User_32.CDS_TEST);
                    int iRet = User_32.ChangeDisplaySettingsEx(name, ref dm, IntPtr.Zero, User_32.CDS_TEST, IntPtr.Zero);

                    if (iRet == User_32.DISP_CHANGE_FAILED)
                    {
                        MessageBox.Show("Unable to process your request");
                        MessageBox.Show("Description: Unable To Process Your Request. Sorry For This Inconvenience.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        //  iRet = User_32.ChangeDisplaySettings(ref dm, User_32.CDS_UPDATEREGISTRY);
                        iRet = User_32.ChangeDisplaySettingsEx(name, ref dm, IntPtr.Zero, User_32.CDS_UPDATEREGISTRY, IntPtr.Zero);
                        switch (iRet)
                        {
                            case User_32.DISP_CHANGE_SUCCESSFUL:
                                {
                                    break;

                                }
                            case User_32.DISP_CHANGE_RESTART:
                                {

                                    MessageBox.Show("Description: 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.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                    break;
                                }
                            default:
                                {

                                    MessageBox.Show("Description: Failed To Change The Resolution (2).", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                    break;
                                }
                        }
                    }

                }
            }