static void printValues() { int curID = 0; bool done = false; do { WinApi.DISPLAY_DEVICE ddOne = new WinApi.DISPLAY_DEVICE(); WinApi.DISPLAY_DEVICE ddTwo = new WinApi.DISPLAY_DEVICE(); ddOne.cb = Marshal.SizeOf(ddOne); ddTwo.cb = Marshal.SizeOf(ddTwo); bool t = WinApi.User_32.EnumDisplayDevices(null, curID, ref ddOne, 0); if (!t) { return; } t = WinApi.User_32.EnumDisplayDevices(ddOne.DeviceName, 0, ref ddTwo, 0); ddOne.DeviceString = ddTwo.DeviceString; WinApi.DEVMODE test = new WinApi.DEVMODE(); WinApi.User_32.EnumDisplaySettings("Test", 4, ref test); int succ = WinApi.User_32.EnumDisplaySettings(ddOne.DeviceName, (-1), ref test); Console.WriteLine(test); Console.WriteLine(ddOne); curID++; } while (!done); }
public void UpdateSize(MyWindowModeEnum?customMode = null) { ProfilerShort.Begin("UpdateSize"); switch (customMode.HasValue ? customMode.Value : m_settings.WindowMode) { case MyWindowModeEnum.Fullscreen: m_renderWindow.OnModeChanged(MyWindowModeEnum.Fullscreen, m_settings.BackBufferWidth, m_settings.BackBufferHeight); break; case MyWindowModeEnum.FullscreenWindow: { WinApi.DEVMODE mode = new WinApi.DEVMODE(); WinApi.EnumDisplaySettings(null, WinApi.ENUM_REGISTRY_SETTINGS, ref mode); VRage.Trace.MyTrace.Watch("Registry display settings", string.Format("{0}x{1}", mode.dmPelsWidth, mode.dmPelsHeight)); m_renderWindow.OnModeChanged(MyWindowModeEnum.FullscreenWindow, mode.dmPelsWidth, mode.dmPelsHeight); break; } case MyWindowModeEnum.Window: m_renderWindow.OnModeChanged(MyWindowModeEnum.Window, m_settings.BackBufferWidth, m_settings.BackBufferHeight); break; } var handler = SizeChanged; if (handler != null) { handler(MyRenderProxy.BackBufferResolution.X, MyRenderProxy.BackBufferResolution.Y, MyRenderProxy.MainViewport); } ProfilerShort.End(); }
public static WinApi.DEVMODE NewDevMode() { WinApi.DEVMODE dm = new WinApi.DEVMODE(); dm.dmDeviceName = new String(new char[31]); dm.dmFormName = new String(new char[31]); dm.dmSize = (ushort)Marshal.SizeOf(dm); return dm; }
public static WinApi.DEVMODE NewDevMode() { WinApi.DEVMODE dm = new WinApi.DEVMODE(); dm.dmDeviceName = new String(new char[31]); dm.dmFormName = new String(new char[31]); dm.dmSize = (ushort)Marshal.SizeOf(dm); return(dm); }
private static PresentParameters CreatePresentParameters(MyRenderDeviceSettings settings, IntPtr windowHandle) { PresentParameters p = new PresentParameters(); p.InitDefaults(); switch (settings.WindowMode) { case MyWindowModeEnum.Fullscreen: p.FullScreenRefreshRateInHz = settings.RefreshRate; p.BackBufferHeight = settings.BackBufferHeight; p.BackBufferWidth = settings.BackBufferWidth; p.Windowed = false; break; case MyWindowModeEnum.FullscreenWindow: { WinApi.DEVMODE mode = new WinApi.DEVMODE(); WinApi.EnumDisplaySettings(null, WinApi.ENUM_REGISTRY_SETTINGS, ref mode); p.FullScreenRefreshRateInHz = 0; p.BackBufferHeight = mode.dmPelsHeight; p.BackBufferWidth = mode.dmPelsWidth; p.Windowed = true; } break; case MyWindowModeEnum.Window: p.FullScreenRefreshRateInHz = 0; p.BackBufferHeight = settings.BackBufferHeight; p.BackBufferWidth = settings.BackBufferWidth; p.Windowed = true; break; } p.DeviceWindowHandle = windowHandle; p.AutoDepthStencilFormat = Format.D24S8; p.EnableAutoDepthStencil = true; p.BackBufferFormat = Format.X8R8G8B8; p.MultiSampleQuality = 0; p.PresentationInterval = settings.VSync ? PresentInterval.One : PresentInterval.Immediate; p.SwapEffect = SwapEffect.Discard; // PresentFlags.Video may cause crash when driver settings has overridden multisampling // We don't need it, it's just hint for driver p.PresentFlags = PresentFlags.DiscardDepthStencil; return(p); }
public static WinApi.DisplaySetting_Results SetScreenPosition(string screen, int x, int y, bool isMain) { WinApi.DEVMODE ndm = NewDevMode(); ndm.dmFields = WinApi.DEVMODE_Flags.DM_POSITION; ndm.dmPosition.x = x; ndm.dmPosition.y = y; int flags = (int)WinApi.DeviceFlags.CDS_UPDATEREGISTRY;// | (int)WinApi.DeviceFlags.CDS_NORESET; if (isMain) { flags |= (int)WinApi.DeviceFlags.CDS_SET_PRIMARY; } return((WinApi.DisplaySetting_Results)WinApi.User_32.ChangeDisplaySettingsEx(screen, ref ndm, (IntPtr)null, flags, IntPtr.Zero)); }
public void OnModeChanged(VRageRender.MyWindowModeEnum windowMode, int width, int height) { if (windowMode == VRageRender.MyWindowModeEnum.Window) { FormBorderStyle = FormBorderStyle.FixedSingle; TopMost = false; } else if (windowMode == VRageRender.MyWindowModeEnum.FullscreenWindow) { FormBorderStyle = FormBorderStyle.None; TopMost = false; // false for fullscreen window, shouldn't matter for true fullscren SizeGripStyle = SizeGripStyle.Hide; } else if (windowMode == VRageRender.MyWindowModeEnum.Fullscreen) { FormBorderStyle = FormBorderStyle.None; // Fullscreen used to have same settings as FullscreenWindow, but Dx11 render required change for Shadow Play to work. // It still seems like TopMost and SizeGripStyle should carry over from other branches. } ClientSize = new System.Drawing.Size(width, height); WinApi.DEVMODE mode = new WinApi.DEVMODE(); WinApi.EnumDisplaySettings(null, WinApi.ENUM_CURRENT_SETTINGS, ref mode); VRage.Trace.MyTrace.Watch("Current display settings", string.Format("{0}x{1}", mode.dmPelsWidth, mode.dmPelsHeight)); if (MyFakes.MOVE_WINDOW_TO_CORNER) { Location = new System.Drawing.Point(mode.dmPelsWidth - width, 0); } else { Location = new System.Drawing.Point(mode.dmPelsWidth / 2 - width / 2, mode.dmPelsHeight / 2 - height / 2); } // TODO: OP! Should be on different place Show(); Activate(); MySandboxGame.Static.UpdateMouseCapture(); }
private static MyRenderDeviceSettings CreateDeviceInternal(IntPtr windowHandle, MyRenderDeviceSettings?settingsToTry) { if (Device != null) { Device.Dispose(); Device = null; } WIC = null; if (settingsToTry != null) { Log.WriteLine("CreateDevice - original settings"); Log.IncreaseIndent(); var originalSettings = settingsToTry.Value; LogSettings(ref originalSettings); } FeatureLevel[] featureLevels = { FeatureLevel.Level_11_0 }; DeviceCreationFlags flags = DeviceCreationFlags.None; #if DEBUG if (VRage.MyCompilationSymbols.DX11Debug) { flags |= DeviceCreationFlags.Debug; } #endif #if !XB1 WinApi.DEVMODE mode = new WinApi.DEVMODE(); WinApi.EnumDisplaySettings(null, WinApi.ENUM_REGISTRY_SETTINGS, ref mode); var settings = settingsToTry ?? new MyRenderDeviceSettings() { AdapterOrdinal = -1, BackBufferHeight = mode.dmPelsHeight, BackBufferWidth = mode.dmPelsWidth, WindowMode = MyWindowModeEnum.Fullscreen, RefreshRate = 60000, VSync = false, }; #else var settings = CreateXB1Settings(); #endif settings.AdapterOrdinal = ValidateAdapterIndex(settings.AdapterOrdinal); if (settings.AdapterOrdinal == -1) { throw new MyRenderException("No supported device detected!", MyRenderExceptionEnum.GpuNotSupported); } m_settings = settings; Log.WriteLine("CreateDevice settings"); Log.IncreaseIndent(); LogSettings(ref m_settings); // If this line crashes cmd this: Dism /online /add-capability /capabilityname:Tools.Graphics.DirectX~~~~0.0.1.0 var adapters = GetAdaptersList(); if (m_settings.AdapterOrdinal >= adapters.Length) { throw new MyRenderException("No supported device detected!", MyRenderExceptionEnum.GpuNotSupported); } var adapterId = adapters[m_settings.AdapterOrdinal].AdapterDeviceId; if (adapterId >= GetFactory().Adapters.Length) { throw new MyRenderException("Invalid adapter id binding!", MyRenderExceptionEnum.GpuNotSupported); } var adapter = GetFactory().Adapters[adapterId]; TweakSettingsAdapterAdHoc(adapter); Device = new Device(adapter, flags, FeatureLevel.Level_11_0); WIC = new ImagingFactory(); // HACK: This is required for Steam overlay to work. Apparently they hook only CreateDevice methods with DriverType argument. try { using (new Device(DriverType.Hardware, flags, FeatureLevel.Level_11_0)){} } catch { } InitDebugOutput(); if (RC != null) { RC.Dispose(); RC = null; } RC = new MyRenderContext(); RC.Initialize(Device.ImmediateContext); m_windowHandle = windowHandle; m_resolution = new Vector2I(m_settings.BackBufferWidth, m_settings.BackBufferHeight); if (!m_initializedOnce) { InitSubsystemsOnce(); m_initializedOnce = true; } if (!m_initialized) { OnDeviceReset(); InitSubsystems(); m_initialized = true; } if (m_swapchain != null) { m_swapchain.Dispose(); m_swapchain = null; } if (m_swapchain == null) { SharpDX.DXGI.Device d = Device.QueryInterface <SharpDX.DXGI.Device>(); Adapter a = d.GetParent <Adapter>(); var factory = a.GetParent <Factory>(); var scDesc = new SwapChainDescription(); scDesc.BufferCount = MyRender11Constants.BUFFER_COUNT; scDesc.Flags = SwapChainFlags.AllowModeSwitch; scDesc.IsWindowed = true; scDesc.ModeDescription.Format = MyRender11Constants.DX11_BACKBUFFER_FORMAT; scDesc.ModeDescription.Height = m_settings.BackBufferHeight; scDesc.ModeDescription.Width = m_settings.BackBufferWidth; scDesc.ModeDescription.RefreshRate.Numerator = m_settings.RefreshRate; scDesc.ModeDescription.RefreshRate.Denominator = 1000; scDesc.ModeDescription.Scaling = DisplayModeScaling.Unspecified; scDesc.ModeDescription.ScanlineOrdering = DisplayModeScanlineOrder.Progressive; scDesc.SampleDescription.Count = 1; scDesc.SampleDescription.Quality = 0; scDesc.OutputHandle = m_windowHandle; scDesc.Usage = Usage.RenderTargetOutput; scDesc.SwapEffect = SwapEffect.Discard; m_swapchain = new SwapChain(factory, Device, scDesc); m_swapchain.GetParent <Factory>().MakeWindowAssociation(m_windowHandle, WindowAssociationFlags.IgnoreAll); } // we start with window always (DXGI recommended) m_settings.WindowMode = MyWindowModeEnum.Window; ApplySettings(settings); return(m_settings); }
static void Main(string[] args) { List <WinApi.DISPLAY_DEVICE> devices = new List <WinApi.DISPLAY_DEVICE>(); List <WinApi.DEVMODE> devModes = new List <WinApi.DEVMODE>(); bool done = false; int curID = 0; do { WinApi.DISPLAY_DEVICE ddOne = new WinApi.DISPLAY_DEVICE(); WinApi.DISPLAY_DEVICE ddTwo = new WinApi.DISPLAY_DEVICE(); ddOne.cb = Marshal.SizeOf(ddOne); ddTwo.cb = Marshal.SizeOf(ddTwo); bool t = WinApi.User_32.EnumDisplayDevices(null, curID, ref ddOne, 0); if (!t) { break; } t = WinApi.User_32.EnumDisplayDevices(ddOne.DeviceName, 0, ref ddTwo, 0); ddOne.DeviceString = ddTwo.DeviceString; WinApi.DEVMODE test = new WinApi.DEVMODE(); WinApi.User_32.EnumDisplaySettings("Test", 4, ref test); int succ = WinApi.User_32.EnumDisplaySettings(ddOne.DeviceName, (-1), ref test); devModes.Add(test); devices.Add(ddOne); curID++; } while (!done); for (int i = 0; i < devices.Count; i++) { Console.WriteLine(devices.ElementAt(i)); Console.WriteLine(devModes.ElementAt(i)); } foreach (System.Windows.Forms.Screen screen in System.Windows.Forms.Screen.AllScreens) { Console.WriteLine(screen.DeviceName); } Console.WriteLine("---------------------------------------------------------------------------"); Console.WriteLine("Changing: " + devices.ElementAt(1)); Console.WriteLine(devModes.ElementAt(1)); Console.WriteLine("---------------------------------------------------------------------------"); Console.ReadKey(); WinApi.DEVMODE d = devModes.ElementAt(1); //d.dmFields = WinApi.DEVMODE_Flags.DM_PELSWIDTH | WinApi.DEVMODE_Flags.DM_PELSHEIGHT; d.dmPelsHeight = 0; d.dmPelsWidth = 0; //d.dmFields |= WinApi.DEVMODE_Flags.DM_POSITION; d.dmPosition.x = 0; Console.WriteLine("Changing the location to: " + d.dmPosition); WinApi.DisplaySetting_Results success = (WinApi.DisplaySetting_Results)WinApi.User_32.ChangeDisplaySettingsEx(devices.ElementAt(1).DeviceName, ref d, (IntPtr)null, ((int)WinApi.DeviceFlags.CDS_UPDATEREGISTRY | (int)WinApi.DeviceFlags.CDS_NORESET), (IntPtr)null); Console.WriteLine("Success: " + success); printValues(); Console.ReadKey(); }
public void OnModeChanged(VRageRender.MyWindowModeEnum windowMode, int width, int height) { if (!MyFakes.ENABLE_DX11_RENDERER) { if (windowMode == VRageRender.MyWindowModeEnum.Window) { FormBorderStyle = FormBorderStyle.FixedSingle; TopMost = false; } else { FormBorderStyle = FormBorderStyle.None; TopMost = false; // false for fullscreen window, shouldn't matter for true fullscren SizeGripStyle = SizeGripStyle.Hide; } } else { if (windowMode == VRageRender.MyWindowModeEnum.Window) { FormBorderStyle = FormBorderStyle.FixedSingle; TopMost = false; } else if (windowMode == VRageRender.MyWindowModeEnum.FullscreenWindow) { FormBorderStyle = FormBorderStyle.None; TopMost = false; // false for fullscreen window, shouldn't matter for true fullscren SizeGripStyle = SizeGripStyle.Hide; } else if (windowMode == VRageRender.MyWindowModeEnum.Fullscreen) { FormBorderStyle = FormBorderStyle.None; } } ClientSize = new System.Drawing.Size(width, height); WinApi.DEVMODE mode = new WinApi.DEVMODE(); WinApi.EnumDisplaySettings(null, WinApi.ENUM_CURRENT_SETTINGS, ref mode); VRage.Trace.MyTrace.Watch("Current display settings", string.Format("{0}x{1}", mode.dmPelsWidth, mode.dmPelsHeight)); if (MyFakes.MOVE_WINDOW_TO_CORNER) { Location = new System.Drawing.Point(mode.dmPelsWidth - width, 0); } else { //if (MyFakes.ENABLE_DX11_RENDERER) //{ // Location = new System.Drawing.Point(0, 0); //} //else //{ // Location = new System.Drawing.Point(mode.dmPelsWidth / 2 - width / 2, mode.dmPelsHeight / 2 - height / 2); //} Location = new System.Drawing.Point(mode.dmPelsWidth / 2 - width / 2, mode.dmPelsHeight / 2 - height / 2); } // TODO: OP! Should be on different place Show(); Activate(); }
public static void SetPrimary(int dn) { string[] devName = new string[3]; if (dn == 1 || dn == 2) { if (dn == 1) { devName[1] = "\\\\.\\DISPLAY" + 1; devName[2] = "\\\\.\\DISPLAY" + 2; } if (dn == 2) { devName[1] = "\\\\.\\DISPLAY" + 2; devName[2] = "\\\\.\\DISPLAY" + 1; } Console.Write("CHANGE PRIMARY DISPLAY TO \\\\.\\DISPLAY" + dn + "\n\n\n"); int deviceID; WinApi.DisplaySetting_Results result = 0; //manual gather - NewPrimary name ---------------------------------------------------- WinApi.DISPLAY_DEVICE ddOne = new WinApi.DISPLAY_DEVICE(); ddOne.cb = Marshal.SizeOf(ddOne); deviceID = 1; WinApi.User_32.EnumDisplayDevices(null, deviceID, ref ddOne, 0); string NewPrimary = devName[1];//ddOne.DeviceName; //manual gather - OldPrimary name ---------------------------------------------------- WinApi.DISPLAY_DEVICE ddThree = new WinApi.DISPLAY_DEVICE(); ddThree.cb = Marshal.SizeOf(ddThree); deviceID = 2; WinApi.User_32.EnumDisplayDevices(null, deviceID, ref ddThree, 0); string OldPrimary = devName[2]; //ACTION 1 start ---------------------------------------------------------------------------- WinApi.DEVMODE ndm1 = NewDevMode(); WinApi.User_32.EnumDisplaySettings(NewPrimary, (int)WinApi.DEVMODE_SETTINGS.ENUM_REGISTRY_SETTINGS, ref ndm1); WinApi.DEVMODE ndm3 = NewDevMode(); ndm3.dmFields = WinApi.DEVMODE_Flags.DM_POSITION; ndm3.dmPosition.x = (int)ndm1.dmPelsWidth; ndm3.dmPosition.y = 0; result = (WinApi.DisplaySetting_Results)WinApi.User_32.ChangeDisplaySettingsEx(OldPrimary, ref ndm3, (IntPtr)null, (int)WinApi.DeviceFlags.CDS_UPDATEREGISTRY | (int)WinApi.DeviceFlags.CDS_NORESET, IntPtr.Zero); Console.Write("Action 1 result:" + result.ToString()); //ACTION 1 end ---------------------------------------------------------------------------- //ACTION 2 start ---------------------------------------------------------------------------- WinApi.DEVMODE ndm2 = NewDevMode(); WinApi.User_32.EnumDisplaySettings(NewPrimary, (int)WinApi.DEVMODE_SETTINGS.ENUM_REGISTRY_SETTINGS, ref ndm2); WinApi.DEVMODE ndm4 = NewDevMode(); ndm4.dmFields = WinApi.DEVMODE_Flags.DM_POSITION; ndm4.dmPosition.x = 0; ndm4.dmPosition.y = 0; result = (WinApi.DisplaySetting_Results)WinApi.User_32.ChangeDisplaySettingsEx(NewPrimary, ref ndm4, (IntPtr)null, (int)WinApi.DeviceFlags.CDS_SET_PRIMARY | (int)WinApi.DeviceFlags.CDS_UPDATEREGISTRY | (int)WinApi.DeviceFlags.CDS_NORESET, IntPtr.Zero); Console.Write("Action 2 result:" + result.ToString()); //ACTION 2 end ---------------------------------------------------------------------------- //ACTION 3 start ---------------------------------------------------------------------------- WinApi.DEVMODE ndm5 = NewDevMode(); result = (WinApi.DisplaySetting_Results)WinApi.User_32.ChangeDisplaySettingsEx(OldPrimary, ref ndm5, (IntPtr)null, (int)WinApi.DeviceFlags.CDS_UPDATEREGISTRY, (IntPtr)null); Console.Write("Action 3.1 result:" + result.ToString()); WinApi.DEVMODE ndm6 = NewDevMode(); result = (WinApi.DisplaySetting_Results)WinApi.User_32.ChangeDisplaySettingsEx(NewPrimary, ref ndm6, (IntPtr)null, (int)WinApi.DeviceFlags.CDS_SET_PRIMARY | (int)WinApi.DeviceFlags.CDS_UPDATEREGISTRY, IntPtr.Zero); Console.Write("Action 3.2 result:" + result.ToString()); //ACTION 3 end ---------------------------------------------------------------------------- } else { Console.Write("Error, Invailed\n"); return; } }
internal static MyRenderDeviceSettings CreateDevice(IntPtr windowHandle, MyRenderDeviceSettings?settingsToTry) { if (Device != null) { Device.Dispose(); Device = null; } FeatureLevel[] featureLevels = { FeatureLevel.Level_11_0 }; DeviceCreationFlags flags = DeviceCreationFlags.None; #if DEBUG_DEVICE flags |= DeviceCreationFlags.Debug; #endif WinApi.DEVMODE mode = new WinApi.DEVMODE(); WinApi.EnumDisplaySettings(null, WinApi.ENUM_REGISTRY_SETTINGS, ref mode); var adapters = GetAdaptersList(); int adapterIndex = settingsToTry.HasValue ? settingsToTry.Value.AdapterOrdinal : -1; adapterIndex = ValidateAdapterIndex(adapterIndex); if (adapterIndex == -1) { throw new MyRenderException("No supporting device detected!", MyRenderExceptionEnum.GpuNotSupported); } var settings = settingsToTry ?? new MyRenderDeviceSettings() { AdapterOrdinal = adapterIndex, BackBufferHeight = mode.dmPelsHeight, BackBufferWidth = mode.dmPelsWidth, WindowMode = MyWindowModeEnum.Fullscreen, RefreshRate = 60000, VSync = false, }; m_settings = settings; Device = new Device(GetFactory().Adapters[adapters[m_settings.AdapterOrdinal].AdapterDeviceId], flags, FeatureLevel.Level_11_0); // HACK: This is required for Steam overlay to work. Apparently they hook only CreateDevice methods with DriverType argument. try { using (new Device(DriverType.Hardware, flags, FeatureLevel.Level_11_0)){} } catch { } if (flags.HasFlag(DeviceCreationFlags.Debug)) { if (DebugDevice != null) { DebugDevice.Dispose(); DebugDevice = null; } DebugDevice = new DeviceDebug(Device); DebugInfoQueue = DebugDevice.QueryInterface <InfoQueue>(); new System.Threading.Thread(ProcessDebugOutput).Start(); } if (ImmediateContext != null) { ImmediateContext.Dispose(); ImmediateContext = null; } ImmediateContext = Device.ImmediateContext; m_windowHandle = windowHandle; m_resolution = new Vector2I(m_settings.BackBufferWidth, m_settings.BackBufferHeight); if (!m_initialized) { InitSubsystems(); m_initialized = true; } if (m_swapchain != null) { m_swapchain.Dispose(); m_swapchain = null; } if (m_swapchain == null) { SharpDX.DXGI.Device d = Device.QueryInterface <SharpDX.DXGI.Device>(); Adapter a = d.GetParent <Adapter>(); var factory = a.GetParent <Factory>(); var scDesc = new SwapChainDescription(); scDesc.BufferCount = MyRender11Constants.BUFFER_COUNT; scDesc.Flags = SwapChainFlags.AllowModeSwitch; scDesc.IsWindowed = true; scDesc.ModeDescription.Format = MyRender11Constants.BACKBUFFER_FORMAT; scDesc.ModeDescription.Height = m_settings.BackBufferHeight; scDesc.ModeDescription.Width = m_settings.BackBufferWidth; scDesc.ModeDescription.RefreshRate.Numerator = m_settings.RefreshRate; scDesc.ModeDescription.RefreshRate.Denominator = 1000; scDesc.ModeDescription.Scaling = DisplayModeScaling.Unspecified; scDesc.ModeDescription.ScanlineOrdering = DisplayModeScanlineOrder.Progressive; scDesc.SampleDescription.Count = 1; scDesc.SampleDescription.Quality = 0; scDesc.OutputHandle = m_windowHandle; scDesc.Usage = Usage.RenderTargetOutput; scDesc.SwapEffect = SwapEffect.Discard; m_swapchain = new SwapChain(factory, Device, scDesc); m_swapchain.GetParent <Factory>().MakeWindowAssociation(m_windowHandle, WindowAssociationFlags.IgnoreAll); } // we start with window always (DXGI recommended) m_settings.WindowMode = MyWindowModeEnum.Window; ApplySettings(settings); return(m_settings); }
public static WinApi.DisplaySetting_Results ApplySettings() { WinApi.DEVMODE ndm = NewDevMode(); return((WinApi.DisplaySetting_Results)WinApi.User_32.ChangeDisplaySettingsEx(null, ref ndm, (IntPtr)null, 0, (IntPtr)null)); }