Sign in to follow this  
Followers 0
XGhosT

WINAPI: how to get monitor brightness

5 posts in this topic

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. .."

#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 )

Share this post


Link to post
Share on other sites



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

Share this post


Link to post
Share on other sites

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 :)

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0