Ejemplo n.º 1
0
        public static List <fixedResolutionSysTray.resolutionSet> getDevices()
        {
            DISPLAY_DEVICE d = new DISPLAY_DEVICE();

            d.cb = Marshal.SizeOf(d);

            DEVMODE dm = GetDevMode();

            List <fixedResolutionSysTray.resolutionSet> devices = new List <fixedResolutionSysTray.resolutionSet>();

            for (int i = 0; i < 5; i++)
            {
                try
                {
                    User_32.EnumDisplayDevices(null, (uint)i, ref d, 1); //Get Device Information
                    if (d.StateFlags != 0)
                    {
                        Boolean isPrimary = d.StateFlags.ToString().Contains("PrimaryDevice");
                        devices.Add(new fixedResolutionSysTray.resolutionSet(i, d.DeviceString, d.DeviceName, isPrimary));
                    }
                }
                catch (Exception) { }
            }


            // Print Device Information
            //Console.WriteLine("DeviceName: {0} \nDeviceString: {1}\nDeviceID: {2}\nDeviceKey {3}\nStateFlags {4}\n", d.DeviceName, d.DeviceString, d.DeviceID, d.DeviceKey, d.StateFlags);
            return(devices);
        }
Ejemplo n.º 2
0
        public CResolution(int a, int b, ref bool success)
        {
            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 != 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:
                    {
                        success = true;
                        break;

                        //successfull change
                    }

                    case User_32.DISP_CHANGE_RESTART:
                    {
                        success = false;
                        //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:
                    {
                        success = false;
                        //MessageBox.Show("Description: Failed To Change The Resolution.\r\n" + iRet + "\r\n" + iWidth.ToString(), "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        break;
                        //failed to change
                    }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        // Token: 0x06000004 RID: 4 RVA: 0x0000205C File Offset: 0x0000025C
        public CResolution(int a, int b)
        {
            Screen   primaryScreen = Screen.PrimaryScreen;
            DEVMODE1 structure     = default(DEVMODE1);

            structure.dmDeviceName = new string(new char[32]);
            structure.dmFormName   = new string(new char[32]);
            structure.dmSize       = (short)Marshal.SizeOf <DEVMODE1>(structure);
            bool flag = User_32.EnumDisplaySettings(null, -1, ref structure) != 0;

            if (flag)
            {
                structure.dmPelsWidth  = a;
                structure.dmPelsHeight = b;
                int  num   = User_32.ChangeDisplaySettings(ref structure, 2);
                bool flag2 = num == -1;
                if (!flag2)
                {
                    num = User_32.ChangeDisplaySettings(ref structure, 1);
                    int num2 = num;
                    if (num2 != 0)
                    {
                        if (num2 != 1)
                        {
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
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 && dm.dmBitsPerPel >= 32)
                {
                    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);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
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
            {
                MessageBox.Show("Unable to process your request");
            }
            return(dm);
        }
        public static void ChangeResolution(int width, int height)
        {
            var screen = Screen.PrimaryScreen;

            var iWidth  = width;
            var iHeight = height;


            var dm = new DEVMODE1 {
                dmDeviceName = new string(new char[32]), 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;

                var 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... in .net framework 4.5, sure.
                    }

                    default:
                    {
                        throw new SystemException("Couldn't change resolution.");
                        //failed to change
                    }
                    }
                }
            }
        }
Ejemplo n.º 8
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);

            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)
                {
                }
                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:
                    {
                        break;
                        //windows 9x series you have to restart
                    }

                    default:
                    {
                        break;
                        //failed to change
                    }
                    }
                }
            }
        }
Ejemplo n.º 9
0
        public void setSupportedResolution(DEVMODE1 dm)
        {
            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
                }
                }
            }
        }
Ejemplo n.º 10
0
        // Arguments
        // int width : Desired Width in pixels
        // int height : Desired Height in pixels
        // int deviceIDIn : DeviceID of the monitor to be changed. DeviceID starts with 0 representing your first
        //                  monitor. For Laptops, the built-in display is usually 0.

        static public string ChangeResolution(int width, int height, int deviceIDIn)
        {
            //Basic Error Check
            uint deviceID = 0;

            if (deviceIDIn < 0)
            {
                deviceID = 0;
            }
            else
            {
                deviceID = (uint)deviceIDIn;
            }

            DISPLAY_DEVICE d = new DISPLAY_DEVICE();

            d.cb = Marshal.SizeOf(d);

            DEVMODE dm = GetDevMode();

            User_32.EnumDisplayDevices(null, deviceID, ref d, 1); //Get Device Information

            // Print Device Information
            Console.WriteLine("DeviceName: {0} \nDeviceString: {1}\nDeviceID: {2}\nDeviceKey {3}\nStateFlags {4}\n", d.DeviceName, d.DeviceString, d.DeviceID, d.DeviceKey, d.StateFlags);

            //Attempt to change settings
            if (0 != User_32.EnumDisplaySettingsEx(d.DeviceName, User_32.ENUM_CURRENT_SETTINGS, ref dm, 0))
            {
                dm.dmPelsWidth  = width;
                dm.dmPelsHeight = height;

                int iRet = User_32.ChangeDisplaySettingsEx(d.DeviceName, ref dm, IntPtr.Zero, ChangeDisplaySettingsFlags.CDS_TEST, IntPtr.Zero);

                if (iRet == (int)DISP_CHANGE.FAILED)
                {
                    return("Unable To Process Your Request. Sorry For This Inconvenience.");
                }
                else
                {
                    iRet = User_32.ChangeDisplaySettingsEx(d.DeviceName, ref dm, IntPtr.Zero, ChangeDisplaySettingsFlags.CDS_UPDATEREGISTRY, IntPtr.Zero);

                    switch (iRet)
                    {
                    case (int)DISP_CHANGE.SUCCESSFUL:
                    {
                        return("Success");
                    }

                    case (int)DISP_CHANGE.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 Resolution.");
                    }
                    }
                }
            }
            else
            {
                return("Failed To Change The Resolution.");
            }
        }
Ejemplo n.º 11
0
        static public string ChangeResolution(int width, int height)
        {
            DEVMODE1 dm = GetDevMode1();

            DISPLAY_DEVICE dsp = new DISPLAY_DEVICE();

            dsp.cb = Marshal.SizeOf(dsp);


            /* for(int i=0; true ; i++) */
            /* { */
            /*     if(!User_32.EnumDisplayDevices(null, i, ref dsp, 0)) */
            /*     { */
            /*         break; */
            /*     } */

            /* Console.WriteLine("DISPLAY_DEVICE: \n" + dsp.ToString()); */

            /*     if(dsp.DeviceString == "Standard VGA Graphics Adapter") */
            /*     { */
            /*         break; */
            /*     } */
            /* } */

            /* Console.WriteLine("Selected DISPLAY_DEVICE: \n" + dsp.ToString()); */

            if (0 != 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("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:
                    {
                        return("Success");
                    }

                    case User_32.DISP_CHANGE_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 Resolution");
                    }
                    }
                }
            }
            else
            {
                return("Failed To Change The Resolution.");
            }
        }