/*public static void ChangeResolution(List<DISPLAY_DEVICE> devices) * { * DEVMODE DevM1 = CreateDevMode(); * DEVMODE DevM2 = CreateDevMode(); * bool enumResult = false; * DisplayChangeResultCode changeResult = default(DisplayChangeResultCode); * * DevM1.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY | DM_POSITION; * * enumResult = User32.EnumDisplaySettings(devices[0].DeviceName, User32.ENUM_CURRENT_SETTINGS, ref DevM1); * * DevM1.dmPelsWidth = 1024; * DevM1.dmPelsHeight = 768; * DevM1.dmDisplayFrequency = 50; * * DevM1.dmPositionX = -1024; * DevM1.dmPositionY = 0; * * DevM1.dmDeviceName = devices[0].DeviceName; * * * DevM2.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY | DM_POSITION; * * enumResult = User32.EnumDisplaySettings(devices[1].DeviceName, User32.ENUM_CURRENT_SETTINGS, ref DevM2); * * * DevM2.dmPelsWidth = 800; * DevM2.dmPelsHeight = 600; * DevM2.dmDisplayFrequency = 50; * * DevM2.dmPositionX = 0; * DevM2.dmPositionY = 0; * * DevM2.dmDeviceName = devices[1].DeviceName; * * changeResult = (DisplayChangeResultCode)User32.ChangeDisplaySettingsEx(devices[0].DeviceName, ref DevM1, IntPtr.Zero, (0), IntPtr.Zero); * * if (changeResult != DisplayChangeResultCode.DISP_CHANGE_SUCCESSFUL) * { * throw new User32Exception("Failed to change resolution: " + changeResult.ToString()); * } * * changeResult = (DisplayChangeResultCode)User32.ChangeDisplaySettingsEx(devices[1].DeviceName, ref DevM2, IntPtr.Zero, (CDS_SET_PRIMARY), IntPtr.Zero); * * if (changeResult != DisplayChangeResultCode.DISP_CHANGE_SUCCESSFUL) * { * throw new User32Exception("Failed to change resolution: " + changeResult.ToString()); * } * * DEVMODE d = new DEVMODE(); * d.dmSize = (short)Marshal.SizeOf(d); * changeResult = (DisplayChangeResultCode)User32.ChangeDisplaySettingsEx(null, ref d, IntPtr.Zero, 0, IntPtr.Zero); * * if (changeResult != DisplayChangeResultCode.DISP_CHANGE_SUCCESSFUL) * { * throw new User32Exception("Failed to change resolution: " + changeResult.ToString()); * } * }*/ public static void ChangeResolution(ref DISPLAY_DEVICE device, int width, int height, int freq, int PositionX, int PositionY) { DEVMODE DevM = CreateDevMode(); bool enumResult = false; DisplayChangeResultCode changeResult = default(DisplayChangeResultCode); DevM.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY | DM_POSITION; enumResult = User32.EnumDisplaySettings(device.DeviceName, User32.ENUM_CURRENT_SETTINGS, ref DevM); DevM.dmPelsWidth = width; DevM.dmPelsHeight = height; DevM.dmDisplayFrequency = freq; DevM.dmPositionX = PositionX; DevM.dmPositionY = PositionY; DevM.dmDeviceName = device.DeviceName; changeResult = (DisplayChangeResultCode)User32.ChangeDisplaySettings(ref DevM, 0); if (changeResult != DisplayChangeResultCode.DISP_CHANGE_SUCCESSFUL) { throw new User32Exception("Failed to change resolution: " + changeResult.ToString()); } }
public static void ChangeResolution(ref DISPLAY_DEVICE device, int width, int height, short bits) { DEVMODE DevM = CreateDevMode(); bool enumResult = false; DisplayChangeResultCode changeResult = default(DisplayChangeResultCode); DevM.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL; enumResult = User32.EnumDisplaySettings(device.DeviceName, User32.ENUM_CURRENT_SETTINGS, ref DevM); DevM.dmPelsWidth = width; DevM.dmPelsHeight = height; DevM.dmBitsPerPel = bits; DevM.dmDeviceName = device.DeviceName; changeResult = (DisplayChangeResultCode)User32.ChangeDisplaySettingsEx(device.DeviceName, ref DevM, IntPtr.Zero, (0), IntPtr.Zero); // faild to change, due to a bad mode? try again with a better mode if (changeResult == DisplayChangeResultCode.DISP_CHANGE_BADMODE) { DevM = FindBestSupportedDeviceMode(device, DevM); changeResult = (DisplayChangeResultCode)User32.ChangeDisplaySettingsEx(device.DeviceName, ref DevM, IntPtr.Zero, (0), IntPtr.Zero); } if (changeResult != DisplayChangeResultCode.DISP_CHANGE_SUCCESSFUL) { throw new User32Exception("Failed to change resolution: " + changeResult.ToString()); } }
public static void ChangeResolution(ref DISPLAY_DEVICE device, int width, int height, short bits, int freq) { DEVMODE DevM = CreateDevMode(); bool enumResult = false; DisplayChangeResultCode changeResult = default(DisplayChangeResultCode); DevM.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL | DM_DISPLAYFREQUENCY; enumResult = User32.EnumDisplaySettings(device.DeviceName, User32.ENUM_CURRENT_SETTINGS, ref DevM); DevM.dmPelsWidth = width; DevM.dmPelsHeight = height; DevM.dmBitsPerPel = bits; DevM.dmDisplayFrequency = freq; DevM.dmDeviceName = device.DeviceName; changeResult = (DisplayChangeResultCode)User32.ChangeDisplaySettingsEx(device.DeviceName, ref DevM, IntPtr.Zero, (0), IntPtr.Zero); if (changeResult != DisplayChangeResultCode.DISP_CHANGE_SUCCESSFUL) { throw new User32Exception("Failed to change resolution: " + changeResult.ToString()); } }