// helper for creating an initialized DEVMODE structure public static Devmode CreateDevmode() { var dm = new Devmode { dmDeviceName = new string(new char[32]), dmFormName = new string(new char[32]) }; dm.dmSize = (short) Marshal.SizeOf(dm); return dm; }
// helper for creating an initialized DEVMODE structure public static Devmode CreateDevmode() { var dm = new Devmode { dmDeviceName = new string(new char[32]), dmFormName = new string(new char[32]) }; dm.dmSize = (short)Marshal.SizeOf(dm); return(dm); }
public void For(int rotation, uint deviceId) { //uint deviceId = 1; // zero origin (i.e. 1 means DISPLAY2) var displayDevice = new DisplayDevice(); var devMode = new Devmode(); displayDevice.cb = Marshal.SizeOf(displayDevice); NativeMethods.EnumDisplayDevices(null, deviceId, ref displayDevice, 0); if (0 != NativeMethods.EnumDisplaySettings( displayDevice.DeviceName, NativeMethods.EnumCurrentSettings, ref devMode)) { int temp = devMode.dmPelsHeight; devMode.dmPelsHeight = devMode.dmPelsWidth; devMode.dmPelsWidth = temp; } devMode.dmDisplayOrientation = rotation; DisplayChange iRet = NativeMethods.ChangeDisplaySettingsEx( displayDevice.DeviceName, ref devMode, IntPtr.Zero, DisplaySettingsFlags.CdsUpdateregistry, IntPtr.Zero); }
public void RunFor(int rotation, uint deviceId) { //uint deviceId = 1; // zero origin (i.e. 1 means DISPLAY2) var displayDevice = new DisplayDevice(); var devMode = new Devmode(); displayDevice.cb = Marshal.SizeOf(displayDevice); NativeMethods.EnumDisplayDevices(null, deviceId, ref displayDevice, 0); if (0 != NativeMethods.EnumDisplaySettings( displayDevice.DeviceName, NativeMethods.EnumCurrentSettings, ref devMode)) { int temp = devMode.dmPelsHeight; devMode.dmPelsHeight = devMode.dmPelsWidth; devMode.dmPelsWidth = temp; } devMode.dmDisplayOrientation = rotation; DisplayChange iRet = NativeMethods.ChangeDisplaySettingsEx( displayDevice.DeviceName, ref devMode, IntPtr.Zero, DisplaySettingsFlags.CdsUpdateregistry, IntPtr.Zero); }
public static extern int EnumDisplaySettings(string lpszDeviceName, int iModeNum, ref Devmode lpDevMode);
internal static extern DisplayChange ChangeDisplaySettingsEx( string lpszDeviceName, ref Devmode lpDevMode, IntPtr hwnd, DisplaySettingsFlags dwflags, IntPtr lParam);
public static extern int ChangeDisplaySettings(ref Devmode lpDevMode, int dwFlags);