1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52:
| public const uint IOCTL_VIDEO_SET_DISPLAY_BRIGHTNESS = 0x23049C;
[DllImport("user32.dll")] public static extern bool EnumDisplayDevices(string lpDevice, uint iDevNum, ref DisplayDevice lpDisplayDevice, uint dwFlags);
public static List<DisplayDevice> GetDisplayDevices() { var res = new List<DisplayDevice>(); var d = new DisplayDevice(); try { for (uint id = 0; HardwareControler.EnumDisplayDevices(null, id, ref d, 0); id++) { d.cb = Marshal.SizeOf(d); res.Add(d); } } catch (Exception ex) { Console.WriteLine(String.Format("{0}", ex.ToString())); }
return res; }
public static void SetBrightness(int value) { var dis = GetDisplayDevices();
foreach (var display in dis) { try { var file = FileInfo32.OpenFile(display.DeviceName); var setts = new DisplayBrigthness(); setts.ucACBrightness = (uint)value; setts.ucDCBrightness = (uint)value; GCHandle handle = GCHandle.Alloc(setts, GCHandleType.Pinned); var p = handle.AddrOfPinnedObject();
uint r = 0; bool res = DeviceIoControl(file, IOCTL_VIDEO_SET_DISPLAY_BRIGHTNESS, p, (uint)Marshal.SizeOf(setts), IntPtr.Zero, 0, ref r, IntPtr.Zero); } catch { } } } |