Ejemplo n.º 1
0
        /// <summary>
        /// 获取支持的分辨率列表
        /// </summary>
        /// <returns></returns>
        public static IList <ScreenSize> GetSupportedScreenResolutions(int deviceIDIn)
        {
            // get current screen info
            var d  = GetDeviceByNo(deviceIDIn);
            var dm = GetDevMode();

            if (0 == User_32.EnumDisplaySettingsEx(d.DeviceName, User_32.ENUM_CURRENT_SETTINGS, ref dm, 0))
            {
                throw new Exception("Can't get current screen info!");
            }

            var devmode = GetDevMode();
            int i       = 0;
            var retList = new List <ScreenSize>();

            while (User_32.EnumDisplaySettingsEx(null, i, ref devmode, 0) == 1)
            {
                if (dm.dmBitsPerPel == devmode.dmBitsPerPel &&
                    dm.dmDefaultSource == devmode.dmDefaultSource &&
                    dm.dmDisplayFlags == devmode.dmDisplayFlags &&
                    devmode.dmPelsHeight > 760)
                {
                    retList.Insert(0, new ScreenSize
                    {
                        Width  = devmode.dmPelsWidth,
                        Height = devmode.dmPelsHeight
                    });
                }
                i++;
            }

            return(retList);
        }
Ejemplo n.º 2
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)
        {
            var     d  = GetDeviceByNo(deviceIDIn);
            DEVMODE dm = GetDevMode();

            //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.");
            }
        }