00001
00002
00003 using System;
00004 using System.Windows.Forms;
00005 using System.Runtime.InteropServices;
00006
00007 [StructLayout(LayoutKind.Sequential)]
00008 public struct DEVMODE1
00009 {
00010 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
00011 public string dmDeviceName;
00012 public short dmSpecVersion;
00013 public short dmDriverVersion;
00014 public short dmSize;
00015 public short dmDriverExtra;
00016 public int dmFields;
00017
00018 public short dmOrientation;
00019 public short dmPaperSize;
00020 public short dmPaperLength;
00021 public short dmPaperWidth;
00022
00023 public short dmScale;
00024 public short dmCopies;
00025 public short dmDefaultSource;
00026 public short dmPrintQuality;
00027 public short dmColor;
00028 public short dmDuplex;
00029 public short dmYResolution;
00030 public short dmTTOption;
00031 public short dmCollate;
00032 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
00033 public string dmFormName;
00034 public short dmLogPixels;
00035 public short dmBitsPerPel;
00036 public int dmPelsWidth;
00037 public int dmPelsHeight;
00038
00039 public int dmDisplayFlags;
00040 public int dmDisplayFrequency;
00041
00042 public int dmICMMethod;
00043 public int dmICMIntent;
00044 public int dmMediaType;
00045 public int dmDitherType;
00046 public int dmReserved1;
00047 public int dmReserved2;
00048
00049 public int dmPanningWidth;
00050 public int dmPanningHeight;
00051 };
00052
00053
00054
00055 class User_32
00056 {
00057 [DllImport("user32.dll")]
00058 public static extern int EnumDisplaySettings(string deviceName, int modeNum, ref DEVMODE1 devMode);
00059 [DllImport("user32.dll")]
00060 public static extern int ChangeDisplaySettings(ref DEVMODE1 devMode, int flags);
00061
00062 public const int ENUM_CURRENT_SETTINGS = -1;
00063 public const int CDS_UPDATEREGISTRY = 0x01;
00064 public const int CDS_TEST = 0x02;
00065 public const int DISP_CHANGE_SUCCESSFUL = 0;
00066 public const int DISP_CHANGE_RESTART = 1;
00067 public const int DISP_CHANGE_FAILED = -1;
00068 }
00069
00070
00071 namespace Resolution
00072 {
00073 public static class ScreenResolution
00074 {
00075
00081 public static void ChangeResolution(int width, int height)
00082 {
00083 Screen screen = Screen.PrimaryScreen;
00084
00085
00086 int iWidth = width;
00087 int iHeight = height;
00088
00089
00090 DEVMODE1 dm = new DEVMODE1();
00091 dm.dmDeviceName = new String(new char[32]);
00092 dm.dmFormName = new String(new char[32]);
00093 dm.dmSize = (short)Marshal.SizeOf(dm);
00094
00095 if (0 != User_32.EnumDisplaySettings(null, User_32.ENUM_CURRENT_SETTINGS, ref dm))
00096 {
00097
00098 dm.dmPelsWidth = iWidth;
00099 dm.dmPelsHeight = iHeight;
00100
00101 int iRet = User_32.ChangeDisplaySettings(ref dm, User_32.CDS_TEST);
00102
00103 if (iRet == User_32.DISP_CHANGE_FAILED)
00104 {
00105 MessageBox.Show("Unable to process your request");
00106 MessageBox.Show("Description: Unable To Process Your Request. Sorry For This Inconvenience.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
00107 }
00108 else
00109 {
00110 iRet = User_32.ChangeDisplaySettings(ref dm, User_32.CDS_UPDATEREGISTRY);
00111
00112 switch (iRet)
00113 {
00114 case User_32.DISP_CHANGE_SUCCESSFUL:
00115 {
00116 break;
00117
00118
00119 }
00120 case User_32.DISP_CHANGE_RESTART:
00121 {
00122
00123 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);
00124 break;
00125
00126 }
00127 default:
00128 {
00129
00130 MessageBox.Show("Description: Failed To Change The Resolution.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
00131 break;
00132
00133 }
00134 }
00135 }
00136
00137 }
00138 }
00139 }
00140 }