In this thread it was mentioned how a software could manage single/multiple monitors. I was curious to see how it could be possible to make it work without the tool.
So I made a script that change brightness (VCP 10) of my primary monitor for a few seconds.
To learn about the VCP commands refer to : https://www.ddcutil.com/vcpinfo_output/
Among other commands, you can turn on/off (VCP D6) secondary monitor, change contrast (VCP 12), etc. In the example you can see (and parse) all commands allowed by your monitor(s).
#include <String.au3>
#include <Array.au3>
#include <WinAPIGdi.au3>
#include <WinAPISysWin.au3>
Local $aPos, $aData = _WinAPI_EnumDisplayMonitors()
If IsArray($aData) Then
ReDim $aData[$aData[0][0] + 1][5]
For $i = 1 To $aData[0][0]
$aPos = _WinAPI_GetPosFromRect($aData[$i][1])
For $j = 0 To 3
$aData[$i][$j + 1] = $aPos[$j]
Next
Next
EndIf
_ArrayDisplay($aData, '_WinAPI_EnumDisplayMonitors')
Local $hWnd = _WinAPI_GetDesktopWindow()
ConsoleWrite($hWnd & @CRLF)
$hMonitor = _WinAPI_MonitorFromWindow($hWnd, $MONITOR_DEFAULTTONEAREST)
ConsoleWrite($hMonitor & @CRLF)
Local $aRet = DllCall("Dxva2.dll", "int", "GetNumberOfPhysicalMonitorsFromHMONITOR", "handle", $hMonitor, "int*", 0)
;_ArrayDisplay($aRet)
Local $iNumberMonitor = $aRet[2]
Const $tag_PHYSICAL_MONITOR = "handle hPhysicalMonitor; wchar strPhysicalMonitorDescription[128];"
Local $tPhysicalMonitor = DllStructCreate(_StringRepeat($tag_PHYSICAL_MONITOR, $iNumberMonitor))
$aRet = DllCall("Dxva2.dll", "int", "GetPhysicalMonitorsFromHMONITOR", "handle", $hMonitor, "int", $iNumberMonitor, "struct*", $tPhysicalMonitor)
;_ArrayDisplay($aRet)
MsgBox($MB_SYSTEMMODAL, "", $tPhysicalMonitor.strPhysicalMonitorDescription)
$aRet = DllCall("Dxva2.dll", "int", "GetCapabilitiesStringLength", "handle", $tPhysicalMonitor.hPhysicalMonitor, "int*", 0)
;_ArrayDisplay($aRet)
Local $iLength = $aRet[2] + 1
Local $tCapabilities = DllStructCreate("char sCapabilities[" & $iLength & "];")
$aRet = DllCall("Dxva2.dll", "int", "CapabilitiesRequestAndCapabilitiesReply", "handle", $tPhysicalMonitor.hPhysicalMonitor, _
"ptr", DllStructGetPtr($tCapabilities), "int", $iLength)
;_ArrayDisplay($aRet)
ConsoleWrite($tCapabilities.sCapabilities & @CRLF)
Local Enum $MC_MOMENTARY, $MC_SET_PARAMETER ; _MC_VCP_CODE_TYPE
$aRet = DllCall("Dxva2.dll", "int", "GetVCPFeatureAndVCPFeatureReply", "handle", $tPhysicalMonitor.hPhysicalMonitor, _
"byte", 0x10, "int*", 0, "int*", 0, "int*", 0)
;_ArrayDisplay($aRet)
ConsoleWrite($aRet[3] = $MC_MOMENTARY ? "Momentary" : ($aRet[3] = $MC_SET_PARAMETER ? "Set" : "Unknown") & @CRLF)
ConsoleWrite("Current value = " & $aRet[4] & "/" & "Maximum = " & $aRet[5] & @CRLF)
Local $iCurrent = $aRet[4]
$aRet = DllCall("Dxva2.dll", "int", "SetVCPFeature", "handle", $tPhysicalMonitor.hPhysicalMonitor, _
"byte", 0x10, "int", 20)
Sleep(5000)
$aRet = DllCall("Dxva2.dll", "int", "SetVCPFeature", "handle", $tPhysicalMonitor.hPhysicalMonitor, _
"byte", 0x10, "int", $iCurrent)
$aRet = DllCall("Dxva2.dll", "int", "DestroyPhysicalMonitors", "int", $iNumberMonitor, "ptr", DllStructGetPtr($tPhysicalMonitor))
;_ArrayDisplay($aRet)