Пример #1
0
        public Boolean changeDisplaySettings(int X, int Y, int refresh, int orientation)
        {
            DEVMODE1[] arDM = getSupportedModes();

            if (arDM != null && arDM.Length > 0)
            {
                for (int i = 0; i < arDM.Length; i++)
                {
                    if (arDM[i].dmPelsWidth == X && arDM[i].dmPelsHeight == Y && arDM[i].dmDisplayFrequency == refresh && arDM[i].dmOrientation == orientation)
                    {
                        DEVMODE1 dmset = new DEVMODE1();
                        dmset.dmDeviceName = new String(new char[32]);
                        dmset.dmFormName   = new String(new char[32]);
                        dmset.dmSize       = (short)Marshal.SizeOf(dmset);
                        if (UnmanagedWin32.EnumDisplaySettings(null, UnmanagedWin32.ENUM_CURRENT_SETTINGS, ref dmset) != 0)
                        {
                            dmset.dmPelsWidth        = X;
                            dmset.dmPelsHeight       = Y;
                            dmset.dmOrientation      = (short)orientation;
                            dmset.dmDisplayFrequency = refresh;

                            int intTest = UnmanagedWin32.ChangeDisplaySettings(ref dmset, UnmanagedWin32.CDS_TEST);

                            if (intTest != UnmanagedWin32.DISP_CHANGE_FAILED)
                            {
                                intTest = UnmanagedWin32.ChangeDisplaySettings(ref dmset, UnmanagedWin32.CDS_UPDATEREGISTRY);
                                if (intTest == UnmanagedWin32.DISP_CHANGE_SUCCESSFUL)
                                {
                                    return(true);
                                }
                                else if (intTest == UnmanagedWin32.DISP_CHANGE_RESTART)
                                {
                                    return(true);
                                }
                            }
                        }
                    }
                }
            }

            return(false);
        }
Пример #2
0
        public DEVMODE1[] getSupportedModes()
        {
            ArrayList alModes = new ArrayList();
            int       intRet  = 1;
            int       intNum  = 0;

            while (intRet != 0)
            {
                DEVMODE1 dm = new DEVMODE1();
                dm.dmDeviceName = new String(new char[32]);
                dm.dmFormName   = new String(new char[32]);
                dm.dmSize       = (short)Marshal.SizeOf(dm);

                intRet = UnmanagedWin32.EnumDisplaySettings(null, intNum++, ref dm);
                if (intRet != 0)
                {
                    alModes.Add(dm);
                }
            }
            return((DEVMODE1[])(alModes.ToArray(typeof(DEVMODE1))));
        }
Пример #3
0
 public static extern int ChangeDisplaySettings(ref DEVMODE1 devMode, int flags);
Пример #4
0
 public static extern int EnumDisplaySettings(string deviceName, int modeNum, ref DEVMODE1 devMode);
Пример #5
0
 public static extern int EnumDisplaySettings(string deviceName, int modeNum, ref DEVMODE1 devMode);
Пример #6
0
 public static extern int ChangeDisplaySettings(ref DEVMODE1 devMode, int flags);
Пример #7
0
        public DEVMODE1[] getSupportedModes()
        {
            ArrayList alModes = new ArrayList();
            int intRet = 1;
            int intNum = 0;

            while (intRet != 0)
            {
                DEVMODE1 dm = new DEVMODE1();
                dm.dmDeviceName = new String(new char[32]);
                dm.dmFormName = new String(new char[32]);
                dm.dmSize = (short)Marshal.SizeOf(dm);

                intRet = UnmanagedWin32.EnumDisplaySettings(null, intNum++, ref dm);
                if (intRet != 0)
                {
                    alModes.Add(dm);
                }
            }
            return (DEVMODE1[])(alModes.ToArray(typeof(DEVMODE1)));
        }
Пример #8
0
        public Boolean changeDisplaySettings(int X, int Y, int refresh, int orientation)
        {
            DEVMODE1[] arDM = getSupportedModes();

            if (arDM != null && arDM.Length > 0)
            {

                for (int i = 0; i < arDM.Length; i++)
                {
                    if (arDM[i].dmPelsWidth == X && arDM[i].dmPelsHeight == Y && arDM[i].dmDisplayFrequency == refresh && arDM[i].dmOrientation == orientation)
                    {

                        DEVMODE1 dmset = new DEVMODE1();
                        dmset.dmDeviceName = new String(new char[32]);
                        dmset.dmFormName = new String(new char[32]);
                        dmset.dmSize = (short)Marshal.SizeOf(dmset);
                        if (UnmanagedWin32.EnumDisplaySettings(null, UnmanagedWin32.ENUM_CURRENT_SETTINGS, ref dmset) != 0)
                        {

                            dmset.dmPelsWidth = X;
                            dmset.dmPelsHeight = Y;
                            dmset.dmOrientation = (short)orientation;
                            dmset.dmDisplayFrequency = refresh;

                            int intTest = UnmanagedWin32.ChangeDisplaySettings(ref dmset, UnmanagedWin32.CDS_TEST);

                            if (intTest != UnmanagedWin32.DISP_CHANGE_FAILED)
                            {

                                intTest = UnmanagedWin32.ChangeDisplaySettings(ref dmset, UnmanagedWin32.CDS_UPDATEREGISTRY);
                                if (intTest == UnmanagedWin32.DISP_CHANGE_SUCCESSFUL)
                                    return true;
                                else if (intTest == UnmanagedWin32.DISP_CHANGE_RESTART)
                                    return true;

                            }

                        }

                    }
                }
            }

            return false;
        }