Popular Post Nine Posted August 8, 2021 Popular Post Posted August 8, 2021 (edited) 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). expandcollapse popup#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) Edited April 29 by Nine Earthshine, seadoggie01, KaFu and 2 others 4 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy
Hadin Posted September 23, 2021 Posted September 23, 2021 turn off monitors: DllCall("Dxva2.dll", "int", "SetVCPFeature", "handle", $tPhysicalMonitor.hPhysicalMonitor, _ "byte", 0xD6, "int",0x05) ;0x04 can too. turn on monitors: DllCall("Dxva2.dll", "int", "SetVCPFeature", "handle", $tPhysicalMonitor.hPhysicalMonitor, _ "byte", 0xD6, "int", 0x01)
SharkyEXE Posted December 7, 2022 Posted December 7, 2022 Hello I have use this script https://www.autoitscript.com/forum/topic/206419-manage-monitors-through-ddcci-channel-using-vcp-commands/?do=findComment&comment=1487077 Please, how includes section #include <WinAPIGdi.au3> in script? My file is broken expandcollapse popup#include <String.au3> #include <Array.au3> ; #include <WinAPIGdi.au3> #include <WinAPISysWin.au3> ; From #include <APIGdiConstants.au3> ; _WinAPI_MonitorFrom*() Global Const $MONITOR_DEFAULTTONEAREST = 2 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) ; From #include <WinAPIGdi.au3> ; #FUNCTION# ==================================================================================================================== ; Author.........: Yashied ; Modified.......: jpm ; =============================================================================================================================== Func _WinAPI_EnumDisplayMonitors($hDC = 0, $tRECT = 0) Local $hEnumProc = DllCallbackRegister('__EnumDisplayMonitorsProc', 'bool', 'handle;handle;ptr;lparam') Dim $__g_vEnum[101][2] = [[0]] Local $aCall = DllCall('user32.dll', 'bool', 'EnumDisplayMonitors', 'handle', $hDC, 'struct*', $tRECT, _ 'ptr', DllCallbackGetPtr($hEnumProc), 'lparam', 0) If @error Or Not $aCall[0] Or Not $__g_vEnum[0][0] Then $__g_vEnum = @error + 10 EndIf DllCallbackFree($hEnumProc) If $__g_vEnum Then Return SetError($__g_vEnum, 0, 0) __Inc($__g_vEnum, -1) Return $__g_vEnum EndFunc ;==>_WinAPI_EnumDisplayMonitors ; From #include <WinAPIGdi.au3> ; #FUNCTION# ==================================================================================================================== ; Author.........: Yashied ; Modified.......: jpm ; =============================================================================================================================== Func _WinAPI_MonitorFromWindow($hWnd, $iFlag = 1) Local $aCall = DllCall('user32.dll', 'handle', 'MonitorFromWindow', 'hwnd', $hWnd, 'dword', $iFlag) If @error Then Return SetError(@error, @extended, 0) Return $aCall[0] EndFunc ;==>_WinAPI_MonitorFromWindow ; From #include <WinAPIGdi.au3> ; #FUNCTION# ==================================================================================================================== ; Author.........: Yashied ; Modified.......: jpm ; =============================================================================================================================== Func _WinAPI_GetPosFromRect($tRECT) Local $aResult[4] For $i = 0 To 3 $aResult[$i] = DllStructGetData($tRECT, $i + 1) If @error Then Return SetError(@error, @extended, 0) Next For $i = 2 To 3 $aResult[$i] -= $aResult[$i - 2] Next Return $aResult EndFunc ;==>_WinAPI_GetPosFromRect
Nine Posted December 7, 2022 Author Posted December 7, 2022 You need to download and install latest version of AutoIt here. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy
SharkyEXE Posted December 7, 2022 Posted December 7, 2022 Nine Hello 1) I download your file https://www.autoitscript.com/site/autoit/downloads/ autoit-v3-setup.zip 2) I install your file autoit-v3-setup.exe 3) I open my script and run 4) Script do not work https://imgur.com/CDxzK1w 5) If run original script i see this window https://imgur.com/2U9I3d8
Nine Posted December 7, 2022 Author Posted December 7, 2022 Don't post images to show script code. To post code, use the appropriate way as described in the link. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy
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