XGhosT Posted April 3, 2008 Posted April 3, 2008 Good afternoon! I'v try to use WINAPI functions to get monitor brightness and get a strange result: Message box "Last Error" does'nt fired, but DLL Call return 0, that is mean "Error" And also, DLLCal give me wrong data (all is zero) :-( From MSDN: "... Return Value If the operation completes successfully, DeviceIoControl returns a nonzero value. If the operation fails or is pending, DeviceIoControl returns zero. To get extended error information, call GetLastError. .." expandcollapse popup#Include <WinAPI.au3> Global Const $IOCTL_VIDEO_QUERY_DISPLAY_BRIGHTNESS = int(0x00230498) Global Const $IOCTL_VIDEO_SET_DISPLAY_BRIGHTNESS = int(0x0023049C) Global Const $IOCTL_VIDEO_QUERY_SUPPORTED_BRIGHTNESS = int(0x00230494) Local $overlap, $ret, $bytesReturned,$lpOverlapped Local $DISPLAY_BRIGHTNESS, $hLCD Local $rs $DISPLAY_BRIGHTNESS = DllStructCreate("ubyte ucDisplayPolicy;ubyte ucACBrightness;ubyte ucDCBrightness") DllStructSetData($DISPLAY_BRIGHTNESS, "ucDisplayPolicy", 0x2) DllStructSetData($DISPLAY_BRIGHTNESS, "ucACBrightness", 0x0) DllStructSetData($DISPLAY_BRIGHTNESS, "ucDCBrightness", 0x0) $bytesReturned = DllStructCreate("int bret") DllStructSetData($bytesReturned, "bret", 1) $hLCD = _WINAPI_CreateFile("\\.\LCD",3,2) $ret = DllCall( _ "kernel32.dll", "int", _ "DeviceIoControl", _ "hwnd", $hLCD, _ "int", $IOCTL_VIDEO_QUERY_DISPLAY_BRIGHTNESS, _ "ptr", 0 , _ "int", 0, _ "ptr", DllStructGetPtr($DISPLAY_BRIGHTNESS), _ "int", DllStructGetSize($DISPLAY_BRIGHTNESS), _ "int", DllStructGetPtr($bytesReturned), _ "ptr", $overlap _ ) if _WinAPI_GetLastError() <> 0 then msgbox(0,"Last Error",_WINAPI_GetLastErrorMessage()) $rs= "Return Code:" & Hex($ret) & ": " & DllStructGetData($bytesReturned,1) & " Bytes, AC=" & DllStructGetData($DISPLAY_BRIGHTNESS, "ucACBrightness",0) & ", DC=" & DllStructGetData($DISPLAY_BRIGHTNESS, "ucDCBrightness",0) MsgBox(0,"Return is ", $rs )
PsaltyDS Posted April 3, 2008 Posted April 3, 2008 Good afternoon! I'v try to use WINAPI functions to get monitor brightness and get a strange result: Message box "Last Error" does'nt fired, but DLL Call return 0, that is mean "Error" And also, DLLCal give me wrong data (all is zero) :-( From MSDN: "... Return Value If the operation completes successfully, DeviceIoControl returns a nonzero value. If the operation fails or is pending, DeviceIoControl returns zero. To get extended error information, call GetLastError. .." Dll calls return arrays:; ... $ret = DllCall( _ "kernel32.dll", "int", _ "DeviceIoControl", _ "hwnd", $hLCD, _ "int", $IOCTL_VIDEO_QUERY_DISPLAY_BRIGHTNESS, _ "ptr", 0 , _ "int", 0, _ "ptr", DllStructGetPtr($DISPLAY_BRIGHTNESS), _ "int", DllStructGetSize($DISPLAY_BRIGHTNESS), _ "int", DllStructGetPtr($bytesReturned), _ "ptr", $overlap _ ) ConsoleWrite("Debug: $ret type = " & VarGetType($ret) & @LF) if _WinAPI_GetLastError() <> 0 then msgbox(0,"Last Error",_WINAPI_GetLastErrorMessage()) $rs= "Return Code:" & Hex($ret[0]) & ": " & DllStructGetData($bytesReturned,1) & " Bytes, AC=" & DllStructGetData($DISPLAY_BRIGHTNESS, "ucACBrightness",0) & ", DC=" & DllStructGetData($DISPLAY_BRIGHTNESS, "ucDCBrightness",0) MsgBox(0,"Return is ", $rs ) Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
tonycst Posted October 11, 2013 Posted October 11, 2013 Question. I am clueless how winapi works, but... Is there a way to set desired brightness ? I want to make a small app with a slider that would enable me to quickly set brightness of my monitor same was as i would in power management window. Thanks a bunch
jaberwacky Posted October 11, 2013 Posted October 11, 2013 You can look into my Monitor Configuration UDF. I'm just about finished with wrapping the MCCS standard into a UDF. Helpful Posts and Websites: AutoIt Wiki | Can't find what you're looking for on the Forum? My scripts: Guiscape | Baroque AU3 Code Formatter | MouseHoverCalltips | SciTe Customization GUI | ActiveWindowTrack Toy | Monitor Configuration UDF
lorenkinzel Posted October 22, 2013 Posted October 22, 2013 I want to make a small app with a slider that would enable me to quickly set brightness of my monitor same was as i would in power management window. '?do=embed' frameborder='0' data-embedContent>>
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now