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 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407
| #include <WinAPI.au3> #include <WinAPIFiles.au3> #include <WinAPIGdi.au3> #include <GUIConstantsEx.au3> #include <GuiSlider.au3> #include <Array.au3> Opt("GUIOnEventMode", 1) $g_szVersion = "RU1Y2-D59U9" If WinExists($g_szVersion) Then Exit AutoItWinSetTitle($g_szVersion) Global Const $Dxva2 = DllOpen("Dxva2.dll") If @error Then Exit 1 Global Const $tagSTRUCT = "HANDLE hPhysicalMonitor;WCHAR szPhysicalMonitorDescription[128];" Global Const $tag_MC_TIMING_REPORT = "BYTE bTimingStatusByte; DWORD dwHorizontalFrequencyInHZ; DWORD dwVerticalFrequencyInHZ" Global Const $tag_DISPLAY_BRIGHTNESS = "byte ucDisplayPolicy; byte ucACBrightness; byte ucDCBrightness" Global Const $IOCTL_VIDEO_QUERY_SUPPORTED_BRIGHTNESS = _WinAPI_IOCTL($FILE_DEVICE_VIDEO, 0x125, $METHOD_BUFFERED, $FILE_ANY_ACCESS) Global Const $IOCTL_VIDEO_QUERY_DISPLAY_BRIGHTNESS = _WinAPI_IOCTL($FILE_DEVICE_VIDEO, 0x126, $METHOD_BUFFERED, $FILE_ANY_ACCESS) Global Const $IOCTL_VIDEO_SET_DISPLAY_BRIGHTNESS = _WinAPI_IOCTL($FILE_DEVICE_VIDEO, 0x127, $METHOD_BUFFERED, $FILE_ANY_ACCESS) Global $idSlider1, $idSlider2, $idButton1, $idButton2, $idLabel1, $idLabel2 Global $hMonitor, $brightness, $contrast, $switch1, $switch2, $VCPReply Global $idLabel3, $idSlider3, $hDevice, $BRIGHTNESS_LCD_Array $hDevice = LCD() If Not @error Then LCD_Set($hDevice) If $hDevice Then _WinAPI_CloseHandle($hDevice) DllClose($Dxva2) Exit EndIf $hMonitor = _WinAPI_MonitorFromWindow(_WinAPI_GetDesktopWindow(), $MONITOR_DEFAULTTOPRIMARY) $hMonitor = _GetPhysicalMonitorsFromHMONITOR($hMonitor) $StringLength = CapabilitiesRequestAndCapabilitiesReply($hMonitor) $Gui = GUICreate("显示器设置", 262, 220, -1, -1) GUISetOnEvent($GUI_EVENT_CLOSE, "_exit") $idSlider1 = GUICtrlCreateSlider(10, 30, 240, 20, BitOR($TBS_TOOLTIPS, $TBS_AUTOTICKS)) GUICtrlSetOnEvent($idSlider1, "Brightness") GUICtrlSetLimit($idSlider1, 100) $idSlider2 = GUICtrlCreateSlider(10, 82, 240, 20, BitOR($TBS_TOOLTIPS, $TBS_AUTOTICKS)) GUICtrlSetOnEvent($idSlider2, "Contrast") GUICtrlSetLimit($idSlider2, 100) $idButton1 = GUICtrlCreateButton("宽屏切换", 16, 160, 85, 25) GUICtrlSetOnEvent($idButton1, "Button1") $idButton2 = GUICtrlCreateButton("恢复默认", 158, 160, 85, 25) GUICtrlSetOnEvent($idButton2, "Button2") $idLabel1 = GUICtrlCreateLabel(" 亮度调节:不可用", 10, 10, 140, 20) $idLabel2 = GUICtrlCreateLabel("对比度调节:不可用", 10, 60, 140, 20) $Combo1 = GUICtrlCreateCombo("", 102, 120, 100, 25, 0x0003) GUICtrlSetOnEvent($Combo1, "Color") GUICtrlCreateLabel("色温调节", 32, 124, 48, 20) _GUICtrlSlider_SetTipSide($idSlider1, $TBTS_TOP) _GUICtrlSlider_SetTipSide($idSlider2, $TBTS_TOP) If $StringLength <> "" Then $VCP_Array = Manage_vcp($StringLength) $VCPReply = _GetVCPFeatureAndVCPFeatureReply($hMonitor, 0x86) If $VCPReply[0] = 0 Then GUICtrlSetState($idButton1, $GUI_DISABLE) $brightness = _GetMonitorBrightness($hMonitor) ConsoleWrite($brightness[1] & @CRLF) $contrast = _GetMonitorContrast($hMonitor) If $brightness[2] <> 0 Then $switch1 = True If $contrast[2] <> 0 Then $switch2 = True If $switch1 Then GUICtrlSetData($idSlider1, $brightness[1]) GUICtrlSetData($idLabel1, "设置亮度:" & $brightness[1]) EndIf If $switch2 Then GUICtrlSetData($idSlider2, $contrast[1]) GUICtrlSetData($idLabel2, "设置对比度:" & $contrast[1]) EndIf For $i = 0 To UBound($VCP_Array) - 1 If $VCP_Array[$i][0] = "14" Then If $VCP_Array[$i][1] <> "" Then $Color_Array = StringSplit($VCP_Array[$i][1], " ", 2) $Color_String = "" For $S = 0 To UBound($Color_Array) - 1 $temp = Select_Color($Color_Array[$S]) If $temp <> "" Then $Color_String &= $temp & "|" Next EndIf ExitLoop EndIf Next If $Color_String <> "" Then $VCPCode = _GetVCPFeatureAndVCPFeatureReply($hMonitor, 0x14) GUICtrlSetData($Combo1, $Color_String, Select_Color($VCPCode[1] - 1)) Else GUICtrlSetData($Combo1, "不支持", "不支持") GUICtrlSetState($Combo1, $GUI_DISABLE) EndIf GUISetState(@SW_SHOW, $Gui) Else WinSetTitle($Gui, "", "未发现DDC/CI") GUICtrlSetData($Combo1, "不支持", "不支持") GUICtrlSetState($idSlider1, $GUI_DISABLE) GUICtrlSetState($idSlider2, $GUI_DISABLE) GUICtrlSetState($idButton1, $GUI_DISABLE) GUICtrlSetState($Combo1, $GUI_DISABLE) GUISetState(@SW_SHOW, $Gui) EndIf
While 1 Sleep(50) WEnd
Func LCD() Local $iDevice $iDevice = _WinAPI_CreateFileEx("\\.\LCD", $OPEN_EXISTING, $GENERIC_READ + $GENERIC_WRITE, $FILE_ANY_ACCESS, 0) Return (@error) ? (SetError(1, _WinAPI_GetLastErrorMessage(), False)) : ($iDevice) EndFunc
Func LCD_Set($iDevice) Local $brightness = DllStructCreate("BYTE[256]") Local $DISPLAY_BRIGHTNESS = DllStructCreate("BYTE[3]") $success = _WinAPI_DeviceIoControl($iDevice, $IOCTL_VIDEO_QUERY_SUPPORTED_BRIGHTNESS, Null, 0, DllStructGetPtr($brightness), 0xff) If $success = False Then Return $BRIGHTNESS_LCD_Array = Brightness_lcd(DllStructGetData($brightness, 1)) $success = _WinAPI_DeviceIoControl($iDevice, $IOCTL_VIDEO_QUERY_DISPLAY_BRIGHTNESS, Null, 0, DllStructGetPtr($DISPLAY_BRIGHTNESS), 0x03) If $success = False Then Return $DISPLAY_BRIGHTNESS_READ = Int(BinaryMid(DllStructGetData($DISPLAY_BRIGHTNESS, 1), 3, 1))
$Gui = GUICreate("内置LCD显示器", 262, 80, -1, -1) GUISetOnEvent($GUI_EVENT_CLOSE, "_exit") $idSlider3 = GUICtrlCreateSlider(10, 30, 240, 20, BitOR($TBS_TOOLTIPS, $TBS_AUTOTICKS)) GUICtrlSetLimit($idSlider3, 100) $idLabel3 = GUICtrlCreateLabel(" 亮度调节:", 10, 10, 140, 20) GUICtrlSetData($idSlider3, $DISPLAY_BRIGHTNESS_READ) GUICtrlSetData($idLabel3, "设置亮度:" & $DISPLAY_BRIGHTNESS_READ) GUICtrlSetOnEvent($idSlider3, "Brightness_set_lcd") GUISetState(@SW_SHOW, $Gui) WinSetTitle($Gui, "", "内置LCD显示器") While 1 Sleep(50) WEnd EndFunc
Func Brightness_set_lcd() Local $lcd_BRIGHTNESS, $DISPLAY_BRIGHTNESS, $success $lcd_BRIGHTNESS = GUICtrlRead($idSlider3) GUICtrlSetData($idLabel3, "设置亮度:" & $lcd_BRIGHTNESS) For $i = 0 To UBound($BRIGHTNESS_LCD_Array) If $lcd_BRIGHTNESS <= $BRIGHTNESS_LCD_Array[$i] Then $DISPLAY_BRIGHTNESS = DllStructCreate($tag_DISPLAY_BRIGHTNESS) DllStructSetData($DISPLAY_BRIGHTNESS, "ucDisplayPolicy", 3) DllStructSetData($DISPLAY_BRIGHTNESS, "ucACBrightness", $BRIGHTNESS_LCD_Array[$i]) DllStructSetData($DISPLAY_BRIGHTNESS, "ucDCBrightness", $BRIGHTNESS_LCD_Array[$i]) $success = _WinAPI_DeviceIoControl($hDevice, $IOCTL_VIDEO_SET_DISPLAY_BRIGHTNESS, DllStructGetPtr($DISPLAY_BRIGHTNESS), DllStructGetSize($DISPLAY_BRIGHTNESS), Null, 0) If $success = False Then Return ExitLoop EndIf Next EndFunc
Func Select_Color($iValue) Local $String If StringIsXDigit($iValue) Then $iValue = Dec($iValue) Switch $iValue Case 1 $String = "sRGB" Case 2 $String = "原生显示" Case 3 $String = "4000K" Case 4 $String = "5000K" Case 5 $String = "6500K" Case 6 $String = "7500K" Case 7 $String = "8200K" Case 8 $String = "9300K" Case 9 $String = "10000K" Case 10 $String = "11500K" Case 11 $String = "User1" Case 12 $String = "User2" Case 13 $String = "User3" Case Else EndSwitch Return $String EndFunc
Func Color() Local $iValue = GUICtrlRead($Combo1) Select Case $iValue = "sRGB" _SetVCPFeature($hMonitor, 0x14, 0x01) Case $iValue = "原生显示" _SetVCPFeature($hMonitor, 0x14, 0x02) Case $iValue = "4000K" _SetVCPFeature($hMonitor, 0x14, 0x03) Case $iValue = "5000K" _SetVCPFeature($hMonitor, 0x14, 0x04) Case $iValue = "6500K" _SetVCPFeature($hMonitor, 0x14, 0x05) Case $iValue = "7500K" _SetVCPFeature($hMonitor, 0x14, 0x06) Case $iValue = "8200K" _SetVCPFeature($hMonitor, 0x14, 0x07) Case $iValue = "9300K" _SetVCPFeature($hMonitor, 0x14, 0x08) Case $iValue = "10000K" _SetVCPFeature($hMonitor, 0x14, 0x09) Case $iValue = "11500K" _SetVCPFeature($hMonitor, 0x14, 0x0a) Case $iValue = "User1" _SetVCPFeature($hMonitor, 0x14, 0x0b) Case $iValue = "User2" _SetVCPFeature($hMonitor, 0x14, 0x0c) Case $iValue = "User3" _SetVCPFeature($hMonitor, 0x14, 0x0d) Case Else EndSelect EndFunc
Func Button1() Local $VCPCode If $switch1 And $switch2 Then $VCPCode = _GetVCPFeatureAndVCPFeatureReply($hMonitor, 0x86) ConsoleWrite($VCPCode[1] & @CRLF) If $VCPCode[1] = 8 Then _SetVCPFeature($hMonitor, 0x86, 0x02) GUICtrlSetData($idButton1, "窄屏") Else _SetVCPFeature($hMonitor, 0x86, 0x08) GUICtrlSetData($idButton1, "宽屏") EndIf EndIf EndFunc
Func Button2() GUICtrlSetData($idButton2, "Reset..") Sleep(250) GUISetState(@SW_HIDE) If $switch1 Or $switch2 Then _RestoreMonitorFactoryDefaults($hMonitor) Sleep(1000) EndIf _DestroyPhysicalMonitor($hMonitor) DllClose($Dxva2) Exit EndFunc
Func Brightness() If Not $switch1 Then Return GUICtrlSetData($idLabel1, "设置亮度:" & GUICtrlRead($idSlider1)) _SetMonitorBrightness($hMonitor, GUICtrlRead($idSlider1)) EndFunc
Func Contrast() If Not $switch2 Then Return GUICtrlSetData($idLabel2, "设置对比度:" & GUICtrlRead($idSlider2)) _SetMonitorContrast($hMonitor, GUICtrlRead($idSlider2)) EndFunc
Func _GetMonitorBrightness(Const $h_monitor) Local Const $MinimumBrightness = DllStructCreate("dword_ptr") Local Const $CurrentBrightness = DllStructCreate("dword_ptr") Local Const $MaximumBrightness = DllStructCreate("dword_ptr") DllCall($Dxva2, "bool", "GetMonitorBrightness", _ "handle", $h_monitor, _ "ptr", DllStructGetPtr($MinimumBrightness), _ "ptr", DllStructGetPtr($CurrentBrightness), _ "ptr", DllStructGetPtr($MaximumBrightness)) If @error Then Return SetError(1, _WinAPI_GetLastErrorMessage(), False) Local Const $brightness[3] = [DllStructGetData($MinimumBrightness, 1), _ DllStructGetData($CurrentBrightness, 1), _ DllStructGetData($MaximumBrightness, 1)] Return $brightness EndFunc
Func _GetMonitorContrast(Const $h_monitor) Local Const $MinimumContrast = DllStructCreate("dword_ptr") Local Const $CurrentContrast = DllStructCreate("dword_ptr") Local Const $MaximumContrast = DllStructCreate("dword_ptr") DllCall($Dxva2, "bool", "GetMonitorContrast", _ "handle", $h_monitor, _ "ptr", DllStructGetPtr($MinimumContrast), _ "ptr", DllStructGetPtr($CurrentContrast), _ "ptr", DllStructGetPtr($MaximumContrast)) If @error Then Return SetError(1, _WinAPI_GetLastErrorMessage(), False) Local Const $contrast[3] = [DllStructGetData($MinimumContrast, 1), _ DllStructGetData($CurrentContrast, 1), _ DllStructGetData($MaximumContrast, 1)] Return $contrast EndFunc
Func _SetMonitorBrightness(Const $h_monitor, Const $NewBrightness) DllCall($Dxva2, "bool", "SetMonitorBrightness", "ptr", $h_monitor, "dword", $NewBrightness) Return (@error ? SetError(1, _WinAPI_GetLastErrorMessage(), False) : True) EndFunc
Func _SetMonitorContrast(Const $h_monitor, Const $contrast) DllCall($Dxva2, "bool", "SetMonitorContrast", "ptr", $h_monitor, "dword", $contrast) Return (@error ? SetError(1, _WinAPI_GetLastErrorMessage(), False) : True) EndFunc
Func _GetPhysicalMonitorsFromHMONITOR(Const $pMonitor) Local $Number = DllStructCreate("DWORD") Local $i, $tagPhysical, $M = 1 $Ret = DllCall($Dxva2, "bool", "GetNumberOfPhysicalMonitorsFromHMONITOR", _ "handle", $pMonitor, _ "ptr", DllStructGetPtr($Number)) $NumberOfMonitors = DllStructGetData($Number, 1) For $i = 1 To $NumberOfMonitors $tagPhysical &= $tagSTRUCT Next $MonitorArray = DllStructCreate($tagSTRUCT) $Ret = DllCall($Dxva2, "bool", "GetPhysicalMonitorsFromHMONITOR", _ "handle", $pMonitor, _ "DWORD", $NumberOfMonitors, _ "ptr", DllStructGetPtr($MonitorArray)) Return DllStructGetData($MonitorArray, 1) EndFunc
Func CapabilitiesRequestAndCapabilitiesReply(Const $h_monitor) Local Const $tagStringLength = DllStructCreate("dword_ptr") DllCall($Dxva2, "bool", "GetCapabilitiesStringLength", "handle", $h_monitor, "ptr", DllStructGetPtr($tagStringLength)) Local Const $CapabilitiesStringLength = DllStructGetData($tagStringLength, 1) Local Const $CapabilitiesString = DllStructCreate("char[" & $CapabilitiesStringLength & ']') DllCall($Dxva2, "bool", "CapabilitiesRequestAndCapabilitiesReply", _ "handle", $h_monitor, _ "ptr", DllStructGetPtr($CapabilitiesString), _ "dword", DllStructGetSize($CapabilitiesString)) Return (@error) ? (SetError(1, _WinAPI_GetLastErrorMessage(), False)) : (DllStructGetData($CapabilitiesString, 1)) EndFunc
Func _RestoreMonitorFactoryDefaults(Const $h_monitor) DllCall($Dxva2, "bool", "RestoreMonitorFactoryDefaults", "ptr", $h_monitor) Return (@error) ? (SetError(1, _WinAPI_GetLastErrorMessage(), False)) : (True) EndFunc
Func _SetVCPFeature(Const $h_monitor, Const $VCPCode, Const $NewValue) DllCall($Dxva2, "bool", "SetVCPFeature", _ "handle", $h_monitor, _ "byte", $VCPCode, _ "dword", $NewValue)
Return (@error) ? (SetError(1, _WinAPI_GetLastErrorMessage(), False)) : (True) EndFunc
Func _GetVCPFeatureAndVCPFeatureReply(Const $h_monitor, Const $VCPCode) Local Const $CurrentValue = DllStructCreate("dword_ptr") Local Const $MaximumValue = DllStructCreate("dword_ptr") Local Const $VCPCodeType = DllStructCreate("dword_ptr") DllCall($Dxva2, "bool", "GetVCPFeatureAndVCPFeatureReply", _ "handle", $h_monitor, _ "byte", $VCPCode, _ "ptr", DllStructGetPtr($VCPCodeType), _ "ptr", DllStructGetPtr($CurrentValue), _ "ptr", DllStructGetPtr($MaximumValue)) If @error Then Return SetError(1, _WinAPI_GetLastErrorMessage(), False) Local Const $VCPFeatureReply[3] = [DllStructGetData($VCPCodeType, 1), DllStructGetData($CurrentValue, 1), DllStructGetData($MaximumValue, 1)] Return $VCPFeatureReply EndFunc
Func Manage_vcp(Const $String) Local $Exp, $i, $tmp, $OUT_String $Exp = StringRegExp($String, "(?<=vcp\()([A-Za-z0-9]{2}[\)\(]?\s?)*(?=\))", 2) If @error Then Return $Exp = StringRegExp($Exp[0], "([0-9A-Fa-f]{2})(\(.+?\))?", 4) If @error Then Return Local $Array[UBound($Exp)][2] For $i = 0 To UBound($Exp) - 1 $tmp = $Exp[$i] $Array[$i][0] = StringStripWS(StringLeft($tmp[0], 2), 8) $OUT_String = StringStripWS(StringTrimLeft($tmp[0], 2), 3) If $OUT_String <> "" Then $OUT_String = StringTrimLeft(StringTrimRight($OUT_String, 1), 1) $Array[$i][1] = $OUT_String EndIf Next Return $Array EndFunc
Func _DestroyPhysicalMonitor(Const $h_monitor) DllCall($Dxva2, "bool", "DestroyPhysicalMonitor", "ptr", $h_monitor) Return (@error) ? (SetError(1, _WinAPI_GetLastErrorMessage(), False)) : (True) EndFunc
Func Brightness_lcd(Const $BRIGHTNESS_Lcd) Local $BRIGHTNESS_String, $tmp, $i For $i = 1 To BinaryLen($BRIGHTNESS_Lcd) $tmp = Int(BinaryMid($BRIGHTNESS_Lcd, $i, 1)) If $i = 1 Then $BRIGHTNESS_String &= $tmp & ";" Else If $tmp = 0 Then ExitLoop $BRIGHTNESS_String &= $tmp & ";" EndIf Next Return StringSplit(StringTrimRight($BRIGHTNESS_String, 1), ";", 2) EndFunc
Func _exit() If $hDevice Then _WinAPI_CloseHandle($hDevice) _DestroyPhysicalMonitor($hMonitor) DllClose($Dxva2) Exit EndFunc
|