svenjatzu Posted August 23, 2019 Posted August 23, 2019 Hi im useing a pc where i got 12 tvs connected to. im useing it like one big tv to watch movies etc. the problem is sometimes a tv just shows black screen then i got to change the frequency from 60 down to 23. also many times the res changes and i got to replace it 1920x1080. is there a way to edit all the connected tvs on startup by script to the res 1920x1080 and 23 hz?
KaFu Posted August 24, 2019 Posted August 24, 2019 (edited) This might work, no guarantee given though... expandcollapse popup#include <WinAPIGdiDC.au3> Global Const $_tag_POINTL = "long x;long y" Global Const $_tag_DEVMODE = "char dmDeviceName[32];ushort dmSpecVersion;ushort dmDriverVersion;short dmSize;" & _ "ushort dmDriverExtra;dword dmFields;" & $_tag_POINTL & ";dword dmDisplayOrientation;dword dmDisplayFixedOutput;" & _ "short dmColor;short dmDuplex;short dmYResolution;short dmTTOption;short dmCollate;" & _ "byte dmFormName[32];ushort LogPixels;dword dmBitsPerPel;int dmPelsWidth;dword dmPelsHeight;" & _ "dword dmDisplayFlags;dword dmDisplayFrequency" Local Const $DM_DISPLAYFREQUENCY = 0x00400000 Local Const $DM_PELSWIDTH = 0x00080000 Local Const $DM_PELSHEIGHT = 0x00100000 Local $DEVMODE = DllStructCreate($_tag_DEVMODE) DllStructSetData($DEVMODE, "dmSize", DllStructGetSize($DEVMODE)) DllStructSetData($DEVMODE, "dmPelsWidth", 1920) DllStructSetData($DEVMODE, "dmPelsHeight", 1080) DllStructSetData($DEVMODE, "dmDisplayFrequency", 23) DllStructSetData($DEVMODE, "dmFields", BitOR($DM_PELSWIDTH, $DM_PELSHEIGHT, $DM_DISPLAYFREQUENCY)) Local Const $CDS_TEST = 0x00000002 Local Const $DISP_CHANGE_SUCCESSFUL = 0 Local $aDevice, $i = 0, $i_Res While 1 $aDevice = _WinAPI_EnumDisplayDevices("", $i) If @error Or Not $aDevice[0] Then ExitLoop If BitAND($aDevice[3], 1) Then ; "The device is part of the desktop" $i_Res = DllCall("user32.dll", "int", "ChangeDisplaySettingsEx", "str", $aDevice[1], "ptr", DllStructGetPtr($DEVMODE), "hwnd", 0, "int", $CDS_TEST, "ptr", 0) If $i_Res[0] = $DISP_CHANGE_SUCCESSFUL Then ; https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-changedisplaysettingsexa $i_Res = DllCall("user32.dll", "int", "ChangeDisplaySettingsEx", "str", $aDevice[1], "ptr", DllStructGetPtr($DEVMODE), "hwnd", 0, "int", 0, "ptr", 0) ; dwflags = 0 > The graphics mode for the current screen will be changed dynamically. If $i_Res[0] = $DISP_CHANGE_SUCCESSFUL Then ConsoleWrite("Display changed for " & $aDevice[1] & @CRLF) EndIf EndIf $i += 1 WEnd Edited August 24, 2019 by KaFu OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2025-May-18) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
svenjatzu Posted August 26, 2019 Author Posted August 26, 2019 The code looks like its gonna do what im looking for, gonna test it asap Theres one more thing id need to include, sometimes some of the screens get deactivated and they need to be activated again, how to add it to the script?
KaFu Posted August 26, 2019 Posted August 26, 2019 Maybe the help-file example for the _SendMessage() function is what you're looking for? #include <MsgBoxConstants.au3> #include <SendMessage.au3> Example() Func Example() Local Const $iOff = 2, $iOn = -1 Opt("WinTitleMatchMode", 4) Local $hWnd = WinGetHandle('classname=Progman') _ToggleMonitor($hWnd, $iOff) Sleep(3000) _ToggleMonitor($hWnd, $iOn) EndFunc ;==>Example Func _ToggleMonitor($hWnd, $iOnOff) Local Const $WM_SYSCOMMAND = 274 Local Const $SC_MONITORPOWER = 61808 _SendMessage($hWnd, $WM_SYSCOMMAND, $SC_MONITORPOWER, $iOnOff) If @error Then MsgBox($MB_SYSTEMMODAL, "_ToggleMonitor", "_SendMessage Error: " & @error) Exit EndIf EndFunc ;==>_ToggleMonitor OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2025-May-18) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
KaFu Posted August 26, 2019 Posted August 26, 2019 Optionally moving the mouse pointer to each screen might work: #include <WinAPIGdi.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 Local $a_InitalMousePos = MouseGetPos() For $i = 1 To $aData[0][0] ; ConsoleWrite($aData[$i][1]+10 &"x"&$aData[$i][2]+10 & @crlf) MouseMove($aData[$i][1] + 10, $aData[$i][2] + 10, 0) Next MouseMove($a_InitalMousePos[0], $a_InitalMousePos[1], 0) EndIf OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2025-May-18) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
svenjatzu Posted August 27, 2019 Author Posted August 27, 2019 The part of switching the res to 1920 and 23hz works nice, it wont force monitors that cant use this res and hz to place it : ) thanks KaFu
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