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: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222:
| Const FILE_DEVICE_VIDEO = $23; METHOD_BUFFERED = 0; FILE_ANY_ACCESS = 0; Const IOCTL_VIDEO_QUERY_SUPPORTED_BRIGHTNESS = FILE_DEVICE_VIDEO Shl 16 Or $125 Shl 2 Or METHOD_BUFFERED Shl 14 Or FILE_ANY_ACCESS; Const IOCTL_VIDEO_QUERY_DISPLAY_BRIGHTNESS = FILE_DEVICE_VIDEO Shl 16 Or $126 Shl 2 Or METHOD_BUFFERED Shl 14 Or FILE_ANY_ACCESS; Const IOCTL_VIDEO_SET_DISPLAY_BRIGHTNESS = FILE_DEVICE_VIDEO Shl 16 Or $127 Shl 2 Or METHOD_BUFFERED Shl 14 Or FILE_ANY_ACCESS;
Type TDisplayBrightness = Packed Record ucDisplayPolicy: Byte; ucACBrightness: Byte; ucDCBrightness: Byte; End;
Const DISPLAYPOLICY_AC = 1; DISPLAYPOLICY_DC = 2; DISPLAYPOLICY_BOTH = 3;
Function IsLCDAvailable: Boolean; Function IsLCD_ACBrightnessSupported(Level: Byte): Boolean; Function IsLCD_DCBrightnessSupported(Level: Byte): Boolean; Function GetLCD_ACBrightnessLevel: Byte; Function GetLCD_DCBrightnessLevel: Byte; Function GetLCD_CurrBrightnessLevel: Byte; Function SetLCD_ACBrightnessLevel(Level: Byte): Boolean; Function SetLCD_DCBrightnessLevel(Level: Byte): Boolean; Function SetLCD_BothBrightnessLevel(Level: Byte): Boolean;
Const LCDDeviceFile = '\\.\LCD';
Function IsLCDAvailable: Boolean; Var LCDHandle: HFILE; Begin Result := False; LCDHandle := CreateFile(LCDDeviceFile, 0, FILE_SHARE_READ Or FILE_SHARE_WRITE, Nil, OPEN_EXISTING, 0, 0); Try Result := IsValidHandle(LCDHandle); Finally If Result Then CloseHandle(LCDHandle); End; End;
Function IsLCD_ACBrightnessSupported(Level: Byte): Boolean; Var LCDHandle: HFILE; BufSize: DWORD; Buf: Array Of Byte; X: Integer; Begin Result := False;
If Not IsLCDAvailable Then Exit;
LCDHandle := CreateFile(LCDDeviceFile, 0, FILE_SHARE_READ Or FILE_SHARE_WRITE, Nil, OPEN_EXISTING, 0, 0); Try BufSize := 256; SetLength(Buf, BufSize); If Not DeviceIoControl(LCDHandle, IOCTL_VIDEO_QUERY_SUPPORTED_BRIGHTNESS, Nil, 0, @Buf[0], BufSize, BufSize, Nil) Then Exit; SetLength(Buf, BufSize); For X := 0 To BufSize - 1 Do If Buf[X] = Level Then Begin Result := True; Exit; End; Finally CloseHandle(LCDHandle); End; End;
Function IsLCD_DCBrightnessSupported(Level: Byte): Boolean; Assembler; Asm CALL IsLCD_ACBrightnessSupported End;
Function GetLCD_ACBrightnessLevel: Byte; Var LCDHandle: HFILE; DispBrightness: TDisplayBrightness; BufSize: DWORD; Begin Result := 0;
If Not IsLCDAvailable Then Exit;
LCDHandle := CreateFile(LCDDeviceFile, 0, FILE_SHARE_READ Or FILE_SHARE_WRITE, Nil, OPEN_EXISTING, 0, 0); Try BufSize := SizeOf(DispBrightness); If Not DeviceIoControl(LCDHandle, IOCTL_VIDEO_QUERY_DISPLAY_BRIGHTNESS, Nil, 0, @DispBrightness, BufSize, BufSize, Nil) Then Exit; Result := DispBrightness.ucACBrightness; Finally CloseHandle(LCDHandle); End; End;
Function GetLCD_DCBrightnessLevel: Byte; Var LCDHandle: HFILE; DispBrightness: TDisplayBrightness; BufSize: DWORD; Begin Result := 0;
If Not IsLCDAvailable Then Exit;
LCDHandle := CreateFile(LCDDeviceFile, 0, FILE_SHARE_READ Or FILE_SHARE_WRITE, Nil, OPEN_EXISTING, 0, 0); Try BufSize := SizeOf(DispBrightness); If Not DeviceIoControl(LCDHandle, IOCTL_VIDEO_QUERY_DISPLAY_BRIGHTNESS, Nil, 0, @DispBrightness, BufSize, BufSize, Nil) Then Exit; Result := DispBrightness.ucDCBrightness; Finally CloseHandle(LCDHandle); End; End;
Function GetLCD_CurrBrightnessLevel: Byte; Var LCDHandle: HFILE; DispBrightness: TDisplayBrightness; BufSize: DWORD; Begin Result := 0;
If Not IsLCDAvailable Then Exit;
LCDHandle := CreateFile(LCDDeviceFile, 0, FILE_SHARE_READ Or FILE_SHARE_WRITE, Nil, OPEN_EXISTING, 0, 0); Try BufSize := SizeOf(DispBrightness); If Not DeviceIoControl(LCDHandle, IOCTL_VIDEO_QUERY_DISPLAY_BRIGHTNESS, Nil, 0, @DispBrightness, BufSize, BufSize, Nil) Then Exit; If DispBrightness.ucDisplayPolicy = DISPLAYPOLICY_AC Then Result := DispBrightness.ucACBrightness Else If DispBrightness.ucDisplayPolicy = DISPLAYPOLICY_DC Then Result := DispBrightness.ucDCBrightness; Finally CloseHandle(LCDHandle); End; End;
Function SetLCD_ACBrightnessLevel(Level: Byte): Boolean; Begin Result := False;
If Not IsLCDAvailable Then Exit; End;
Function SetLCD_DCBrightnessLevel(Level: Byte): Boolean; Begin Result := False;
If Not IsLCDAvailable Then Exit; End;
Function SetLCD_BothBrightnessLevel(Level: Byte): Boolean; Begin Result := False;
If Not IsLCDAvailable Then Exit; End; |