private bool GenerateNewMode(int id) { var MyInfoEnumProc = new DISPLAY_DEVICE(); MyInfoEnumProc.cb = Marshal.SizeOf(MyInfoEnumProc);//構造体のサイズを設定 if (!DisplayDevice.EnumDisplayDevices(IntPtr.Zero, id, ref MyInfoEnumProc, 0)) { return false; } // initialize the DEVMODE structure var dm = new DEVMODE(); dm.dmDeviceName = new string(new char[32]); dm.dmFormName = new string(new char[32]); dm.dmSize = (short)Marshal.SizeOf(dm); if (!DisplayDevice.EnumDisplaySettings (MyInfoEnumProc.DeviceName, DisplayDevice.ENUM_CURRENT_SETTINGS, ref dm)) { return false; } this.Mode = dm; this.Name = MyInfoEnumProc.DeviceName; return true; }
[DllImport("user32.dll")]//"coredll.dll")] public static extern int ChangeDisplaySettingsEx( string lpszDeviceName, ref DEVMODE lpDevMode, IntPtr hwnd, int dwflags, IntPtr lParam);
public static extern int ChangeDisplaySettings( ref DEVMODE devMode, int flags);
public static extern bool EnumDisplaySettings( string devName, int modeNum, ref DEVMODE devMode);
public static extern int ChangeDisplaySettingsEx( string lpszDeviceName, ref DEVMODE lpDevMode, IntPtr hwnd, int dwflags, IntPtr lParam);