tsj017
发表于 2023-10-15 22:53:14
繁星 发表于 2023-10-13 13:43
你这程序自带定时功能啊,是你没发现还是定时功能是摆设
那个定时功能要配相关设备才能用,本次采购清单上没有
tsj017
发表于 2023-10-15 22:53:44
haijie1223 发表于 2023-10-11 20:45
https://www.autoitx.com/thread-20809-1-1.html
用这个试试
好的,我看看先
tsj017
发表于 2023-10-15 23:47:03
haijie1223 发表于 2023-10-11 20:45
https://www.autoitx.com/thread-20809-1-1.html
用这个试试
这个不懂用,看不懂,运行没反应
tsj017
发表于 2023-10-16 20:19:07
haijie1223 发表于 2023-10-11 20:45
https://www.autoitx.com/thread-20809-1-1.html
用这个试试
怎么用,能弄个例子看看吗
haijie1223
发表于 2023-10-16 23:55:13
tsj017 发表于 2023-10-16 20:19
怎么用,能弄个例子看看吗
SetDisplayBrightness(50, 50)
tsj017
发表于 2023-10-17 22:08:49
haijie1223 发表于 2023-10-16 23:55
SetDisplayBrightness(50, 50)
没反应,在代码前面,程序后面,所有代码后面加上,都没反应
haijie1223
发表于 2023-10-18 08:18:46
tsj017 发表于 2023-10-17 22:08
没反应,在代码前面,程序后面,所有代码后面加上,都没反应
台式机?
haijie1223
发表于 2023-10-18 08:20:26
tsj017 发表于 2023-10-17 22:08
没反应,在代码前面,程序后面,所有代码后面加上,都没反应
https://www.autoitx.com/thread-11443-1-1.html
用这个吧
tsj017
发表于 2023-10-18 21:46:23
haijie1223 发表于 2023-10-18 08:18
台式机?
是的,台式机
tsj017
发表于 2023-10-19 00:30:57
haijie1223 发表于 2023-10-18 08:20
https://www.autoitx.com/thread-11443-1-1.html
用这个吧
这个确实可以改亮度,但是:
1,我外接了显示器,这个程序是两个显示器亮度同时改变,我只想改变扩展输出,实在不行,两个同时改也能接受吧。
2,这个是通过滑块赋值改亮度,而我希望是定时赋值改亮度。我直接赋值亮度却没反应,帮看下我写的为啥没反应
#include <WinAPI.au3>
#include <GUISlider.au3>
Const $WM_HSCROLL = 0x0114 ;定义常量 $WM_HSCROLL = 0x0114
Local $hGUI, $iSlider, $tBuffer, $hDC,$ld ;声明变量 $hGUI, $iSlider, $tBuffer, $hDC
Global $H = @HOUR ;定义小时
$M = @MIN ;定义分钟
$S = @SEC ;定义秒
If $H>=7 AND $H<10 Then ;早上7到10点,把亮度调为30%
; MsgBox(4096,"", "早退.")
$ld=30
ElseIf $H>=10AND $H<18 Then ;早上10到下午6点,把亮度调为150%
;MsgBox(4096,"", "还没到时间.")
$ld=150
Else
If $H>=18AND $H<23 Then ;下午6到晚上11点,把亮度调为255%
; MsgBox(4096,"", "Value might be hexadecimal!")
$ld=255
EndIf
EndIf
$hDC = _WinAPI_GetDC(0) ;检索窗口客户区的显示设备环境句柄
$tBuffer = _GetDisplayBrightness($hDC)
;$hGUI = GUICreate("Set display brightness", 200, 70);创建窗口
;$iSlider = GUICtrlCreateSlider(20, 20, 160, 20) ; 创建滑动条
;_GUICtrlSlider_SetRangeMin(-1, 12) ;设置滑块最小逻辑位置
;_GUICtrlSlider_SetRangeMax(-1, 256) ;设置滑块的最大逻辑位置
;_GUICtrlSlider_SetRange(-1, 12, 256) ;设置滑块最低和最高逻辑位置范围.
;GUICtrlSetData(-1, DllStructGetData($tBuffer, "r", 2)) ;修改控件数据
GUIRegisterMsg($WM_HSCROLL, "_WM_HSCROLL") ;注册 Windows 消息 ID (WM_MSG) 的自定义函数.
GUISetState() ;调整窗口状态,默认显示
Do
Until GUIGetMsg() = -3 ;获取窗口事件消息,不明白这个
$tBuffer = 0
_WinAPI_ReleaseDC(0, $hDC) ;释放设备环境
Func _WM_HSCROLL($hWnd, $iMsg, $iwParam, $ilParam)
Local $iValue =$ld;GUICtrlRead($iSlider) ;读取滑块数据
For $i = 1 To 255
DllStructSetData($tBuffer, "r", $i * $iValue, $i + 1);设置结构元素的数据(结构, 元素, 值[, 索引]))
DllStructSetData($tBuffer, "g", $i * $iValue, $i + 1)
DllStructSetData($tBuffer, "b", $i * $iValue, $i + 1)
Next
_SetDisplayBrightness($hDC, $tBuffer)
EndFunc ;==>_WM_HSCROLL
Func _SetDisplayBrightness($hDC, ByRef $tBuffer)
Local $iResult
$iResult = DllCall("Gdi32.dll", "int", "SetDeviceGammaRamp", "hWnd", $hDC, _
"ptr", DllStructGetPtr($tBuffer))
Return $iResult
EndFunc ;==>_SetDisplayBrightness
Func _GetDisplayBrightness($hDC)
Local $iResult, $tBuffer
$tBuffer = DllStructCreate("short r;short g;short b")
$iResult = DllCall("Gdi32.dll", "int", "GetDeviceGammaRamp", "hWnd", $hDC, _
"ptr", DllStructGetPtr($tBuffer))
If $iResult = 0 Then $tBuffer = 0
Return $tBuffer
EndFunc ;==>_GetDisplayBrightness
haijie1223
发表于 2023-10-19 08:18:02
tsj017 发表于 2023-10-19 00:30
这个确实可以改亮度,但是:
1,我外接了显示器,这个程序是两个显示器亮度同时改变,我只想改变扩展 ...
_SetValue(50)
Func _SetValue($iValue)
For $i = 1 To 255
DllStructSetData($tBuffer, "r", $i * $iValue, $i + 1);设置结构元素的数据(结构, 元素, 值[, 索引]))
DllStructSetData($tBuffer, "g", $i * $iValue, $i + 1)
DllStructSetData($tBuffer, "b", $i * $iValue, $i + 1)
Next
_SetDisplayBrightness($hDC, $tBuffer)
EndFunc ;==>_WM_HSCROLL
tsj017
发表于 2023-10-19 20:45:14
haijie1223 发表于 2023-10-19 08:18
_SetValue(50)
Func _SetValue($iValue)
For $i = 1 To 255
搞不定,看我改的问题出在哪,非要拖动滑块才改亮度,如果把30到35行注释运行就没反应,不注释就得拖动滑块,一拖亮度就改变,再怎么拖都不变,说明亮度值被固定成功了,但是怎么脱离gui窗口,我没看到后面程序哪一行跟他有关系
#include <WinAPI.au3>
#include <GUISlider.au3>
Const $WM_HSCROLL = 0x0114
Local $hGUI, $iSlider, $tBuffer, $hDC
Global $H = @HOUR
$M = @MIN
$S = @SEC
If $H>=7 AND $H<10 Then
$iValue=30
ElseIf $H>=10AND $H<18 Then
$iValue=250
ElseIf $H>=18AND $H<23 Then
$iValue=55
EndIf
EndIf
$hDC = _WinAPI_GetDC(0)
$tBuffer = _GetDisplayBrightness($hDC)
$hGUI = GUICreate("Set display brightness", 200, 70)
$iSlider = GUICtrlCreateSlider(20, 20, 160, 20)
_GUICtrlSlider_SetRangeMin(-1, 28)
_GUICtrlSlider_SetRangeMax(-1, 256)
_GUICtrlSlider_SetRange(-1, 28, 256)
GUICtrlSetData(-1, DllStructGetData($tBuffer, "r", 2))
GUIRegisterMsg($WM_HSCROLL, "_WM_HSCROLL")
GUISetState()
Do
Until GUIGetMsg() = -3
$tBuffer = 0
_WinAPI_ReleaseDC(0, $hDC)
Func _WM_HSCROLL($hWnd, $iMsg, $iwParam, $ilParam)
For $i = 0 To 255
DllStructSetData($tBuffer, "r", $i * $iValue, $i + 1)
DllStructSetData($tBuffer, "g", $i * $iValue, $i + 1)
DllStructSetData($tBuffer, "b", $i * $iValue, $i + 1)
Next
_SetDisplayBrightness($hDC, $tBuffer)
EndFunc ;==>_WM_HSCROLL
Func _SetDisplayBrightness($hDC, ByRef $tBuffer)
Local $iResult
$iResult = DllCall("Gdi32.dll", "int", "SetDeviceGammaRamp", "hWnd", $hDC, _
"ptr", DllStructGetPtr($tBuffer))
Return $iResult
EndFunc ;==>_SetDisplayBrightness
Func _GetDisplayBrightness($hDC)
Local $iResult, $tBuffer
$tBuffer = DllStructCreate("short r;short g;short b")
$iResult = DllCall("Gdi32.dll", "int", "GetDeviceGammaRamp", "hWnd", $hDC, _
"ptr", DllStructGetPtr($tBuffer))
If $iResult = 0 Then $tBuffer = 0
Return $tBuffer
EndFunc ;==>_GetDisplayBrightness
haijie1223
发表于 2023-10-19 23:33:03
tsj017 发表于 2023-10-19 20:45
搞不定,看我改的问题出在哪,非要拖动滑块才改亮度,如果把30到35行注释运行就没反应,不注释就得拖动滑 ...
我给你的代码你都不用,问题就在这里
tsj017
发表于 2023-10-20 19:19:06
haijie1223 发表于 2023-10-19 23:33
我给你的代码你都不用,问题就在这里
直接复制过去,运行没反应,所有才瞎改
tsj017
发表于 2023-10-20 19:27:21
haijie1223 发表于 2023-10-19 23:33
我给你的代码你都不用,问题就在这里
这样可以,终于有反应了:face (1):
#include <WinAPI.au3>
#include <GUISlider.au3>
Const $WM_HSCROLL = 0x0114
Local $hGUI, $iSlider, $tBuffer, $hDC
$hDC = _WinAPI_GetDC(0)
$tBuffer = _GetDisplayBrightness($hDC)
#cs
$hGUI = GUICreate("Set display brightness", 200, 70)
$iSlider = GUICtrlCreateSlider(20, 20, 160, 20)
_GUICtrlSlider_SetRangeMin(-1, 128)
_GUICtrlSlider_SetRangeMax(-1, 256)
_GUICtrlSlider_SetRange(-1, 128, 256)
GUICtrlSetData(-1, DllStructGetData($tBuffer, "r", 2))
;GUIRegisterMsg($WM_HSCROLL, "_WM_HSCROLL")
GUISetState()
Do
Until GUIGetMsg() = -3
$tBuffer = 0
_WinAPI_ReleaseDC(0, $hDC)
#ce
_SetValue(250)
Func _SetValue($iValue)
For $i = 1 To 255
DllStructSetData($tBuffer, "r", $i * $iValue, $i + 1);设置结构元素的数据(结构, 元素, 值[, 索引]))
DllStructSetData($tBuffer, "g", $i * $iValue, $i + 1)
DllStructSetData($tBuffer, "b", $i * $iValue, $i + 1)
Next
_SetDisplayBrightness($hDC, $tBuffer)
EndFunc ;==>_WM_HSCROLL
#cs
Func _WM_HSCROLL($hWnd, $iMsg, $iwParam, $ilParam)
; Local $iValue = GUICtrlRead($iSlider)
For $i = 0 To 255
DllStructSetData($tBuffer, "r", $i * $iValue, $i + 1)
DllStructSetData($tBuffer, "g", $i * $iValue, $i + 1)
DllStructSetData($tBuffer, "b", $i * $iValue, $i + 1)
Next
_SetDisplayBrightness($hDC, $tBuffer)
EndFunc ;==>_WM_HSCROLL
#ce
Func _SetDisplayBrightness($hDC, ByRef $tBuffer)
Local $iResult
$iResult = DllCall("Gdi32.dll", "int", "SetDeviceGammaRamp", "hWnd", $hDC, _
"ptr", DllStructGetPtr($tBuffer))
Return $iResult
EndFunc ;==>_SetDisplayBrightness
Func _GetDisplayBrightness($hDC)
Local $iResult, $tBuffer
$tBuffer = DllStructCreate("short r;short g;short b")
$iResult = DllCall("Gdi32.dll", "int", "GetDeviceGammaRamp", "hWnd", $hDC, _
"ptr", DllStructGetPtr($tBuffer))
If $iResult = 0 Then $tBuffer = 0
Return $tBuffer
EndFunc ;==>_GetDisplayBrightness