Ejemplo n.º 1
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.º 2
0
 public static extern bool EnumDisplayDevices(string lpDevice, uint iDevNum, ref DISPLAY_DEVICE lpDisplayDevice, uint dwFlags);
Ejemplo n.º 3
0
 public static extern bool EnumDisplayDevices(string deviceName, int modeNum, ref DISPLAY_DEVICE dsp, int flags);
Ejemplo n.º 4
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.");
            }
        }
Ejemplo n.º 5
0
        private static DISPLAY_DEVICE GetDisplayDeviceStruct()
        {
            DISPLAY_DEVICE dsp = new DISPLAY_DEVICE();

            return(dsp);
        }