Davegbuf Posted July 12, 2023 Posted July 12, 2023 I have been using AutoIt for a long time but what I would like to do here is a bit above my understanding. I am hoping that someone with more knowledge about AutoIt and PowerShell than myself can help translate the three main command-lines so that I can develop it into an AutoIt function. This would allow more flexibly and integration with my existing AutoIt code projects. Background Info: I have a Powershell script that can change the Windows display scale percentage on the fly without having to reboot or log off. My knowlege of Powershell is very basic, so what I did was modify the original PowerShell script as you can see in the attached screenshot below. This changes the dispaly scale to 125% when I run it in natively. As you can also see, I created a variable called $scaling and assigned it a value of 1 to make it a straight script because I don't know how to pass values to it externally from a BAT or AutoIt script as-is. Observations: It seems like the only thing the PS script does is get some info from the user32.dll and then do a couple of API calls. I noticed that AutoIt has a _WinAPI_SystemParametersInfo() and DllCall() functions which I think would work the same way antively in AutoIt. The problem for me is that the Help Information, the MSDN website info, and Powershell information on the internet is very confusing and I don't understand it very well. I am a PC administrator, and not a developer so many of these programming concepts are aove my understanding. I would like to do the same as the PS1 script in Autoit. If anyone can help me with those few lines, I can create a function out of it that I would gladly share with the AutoIt community. Original Powershell script source:https://stackoverflow.com/questions/10365394/change-windows-font-size-dpi-in-powershell/68760240#68760240 Set_Scale.ps1
Andreik Posted July 12, 2023 Posted July 12, 2023 It's a simple call of SystemParametersInfo. #include <WinAPISys.au3> ; SPI_SETLOGICALDPIOVERRIDE = 0x009F ; SPIF_UPDATEINIFILE = 0x0001 _WinAPI_SystemParametersInfo(0x009F, $iScaling, Null, 0x0001) For whatever reason MSDN has a note for SPI_SETLOGICALDPIOVERRIDE and say Do not use. Davegbuf 1
Davegbuf Posted July 18, 2023 Author Posted July 18, 2023 (edited) On 7/12/2023 at 2:44 PM, Andreik said: _WinAPI_SystemParametersInfo(0x009F, $iScaling, Null, 0x0001) Andreik, I saw your reply over the weekend, and I was very excited to give it a try. You did exactly what I needed with one single line of code and it is much simpler than the original PowerShell script. It worked so well that I made a command line utility with a function where I could scale my laptop display to any percentage by passing a string as a parameter like: 100%, 125%, 150%, 175% or it’s equivalent numerical value 0,1,2, or 3. I’m afraid it will not be very useful as-is. Nonetheless, I included it further towards the end so you can see it. The problem is that I think I discovered why the MSDN site has a note for SPI_SETLOGICALDPIOVERRIDE that says Do not use. When I ran the same script on a different laptop, the values I passed would give different results. For example, I might use the 125% value, and the machine would scale to 175% instead. Here is an interesting read on that undocumented Microsoft feature: https://stackoverflow.com/questions/35233182/how-can-i-change-windows-10-display-scaling-programmatically-using-c-sharp/62916586#62916586 I bookmarked the articles to circle back later when I can free up some spare time. In short, it looks like the values 0 – 3 are index values relative to a specific value that represents the OS “recommended” percentage for the display. For example, the screenshot below shows 100% is recommended for the machine; therefore, 0 represents the recommended value index. If I use your line of code a value of 1 as seen below, then the display scales to the next step up, 125%. _WinAPI_SystemParametersInfo(0x009F,1, Null, 0x0001) The other laptop where my test failed has a recommended value of 150%, so I can run the same script with a value of -1 as seen below to bring it to 125% since this percentage is the next step below the recommended (0 index) value. _WinAPI_SystemParametersInfo(0x009F,-1, Null, 0x0001) The same article writer explains more in this article which I added an excerpt below. https://stackoverflow.com/questions/35233182/how-can-i-change-windows-10-display-scaling-programmatically-using-c-sharp/58066736#58066736 Note on DPI scaling on windows 1. DPI scaling is property of the source and not of target (see ViPN for these terminologies). 2. DPI scaling of a display is dependent on 3 factors - resolution, physical size of display, expected viewing distance. The exact formula which Windows uses to arrive at recommended value is unknown. 3. In OS parlance DPI scaling values have a meaning when compared against the recommended DPI scaling of a display. Thus although we see 100%, 125%, etc. in system settings app, the OS doesn't understand scaling in percentages. Instead number of steps above, or below recommended scaling is used. For eg. a DPI scaling value of -1 would mean 1 step lower than the recommended DPI scaling. So if for a monitor the recommended value is 150%, -1 would mean 125%. I used WinDbg Preview (MS Store), and Ghidra to do the reverse engineering. There was a point when I was about to give up for the lack of IDA Pro license, when someone suggested me Ghidra. I have been a fan ever since. First Draft expandcollapse popup#AutoIt3Wrapper_UseX64=y #include <WinAPISys.au3> ; --- (NOTE: Cannot scale Display on a Terminal Services (RDP) session. The environment variable SESSIONNAME will be Null("") ; on the current machine if running in a Terminal Services session; or "Console" id running on a computer standard session. If EnvGet('SESSIONNAME')<>'Console' Then MsgBox(16,'Session Error','Cannot scale Display on a Terminal Services (RDP) session.',60) Exit(-1) EndIf ; --- Set Display Scale Percentage according to the value passed via the command line. If $CmdLine[0]=1 Then $bReturn=_SetWinDisplayScalePercent($CmdLine[1]) If $CmdLine[0]<>1 OR $bReturn=False Then MsgBox(16,'Syntax Error','Syntax:' & @CRLF & @CRLF & 'Set_Windows_Display_Scale_Percent.exe [value | percentage]' & @CRLF & @CRLF _ & ' "0" or "100%" (default)' & @CRLF & ' "1" or "125%"' & @CRLF & ' "2" or "150%"' & @CRLF & ' "3" or "175%"' _ & @CRLF & @CRLF & 'Example 1 - Set scale to 125% : ' & @CRLF & @CRLF & ' Set_Windows_Display_Scale_Percent.exe 125%' & @CRLF & @CRLF _ & 'Example 2 - Set scale to 150% using value 2 :' & @CRLF & @CRLF & ' Set_Windows_Display_Scale_Percent.exe 2',60) Endif Exit ; #FUNCTION# ==================================================================================================================== ; Script Function: Change the Windows Display Scale Percentage on the fly without the need to reboot. Unlike other ; solutions found on the internet which require modifying the registry and a system reboot, this ; solution takes effect immediately. ; This AutoIt function is a conversion based on an original Powershell script that was posted on the internet ; by IanXue-MSFT on https://learn.microsoft.com/en-us/answers/questions/197944/batch-file-or-tool-like-powertoy-to-change-the-res.html ; ------------------------------------------------------------------------------------------------------------------------------ ; -- Sets the Display Scale Percentage to 100% or optionally to the value specified by $iScale ; ; _SetWinDisplayScalePercent([$iScale=0]) ; ; Parameter $iScale: ; # $iScale = 0 : 100% (default) ; # $iScale = 1 : 125% ; # $iScale = 2 : 150% ; # $iScale = 3 : 175% ; ; Return Value - Returns True (success) or False (failed) as returned by _WinAPI_SystemParametersInfo() ; Returns @error and extended as returned by _WinAPI_SystemParametersInfo() ; ; =============================================================================================================================== Func _SetWinDisplayScalePercent($ScalePercent='') Select Case $ScalePercent='' OR $ScalePercent='0' OR $ScalePercent='100%' $iScale=0 ; --- Default Case $ScalePercent='1' OR $ScalePercent='125%' $iScale=1 Case $ScalePercent='2' OR $ScalePercent='150%' $iScale=2 Case $ScalePercent='3' OR $ScalePercent='175%' $iScale=3 Case Else Return SetError(-1,-1,False) EndSelect ; --- Set the Display Scale ; SPI_SETLOGICALDPIOVERRIDE = 0x009F ; SPIF_UPDATEINIFILE = 0x0001 $iReturn=_WinAPI_SystemParametersInfo(0x009F, $iScale, Null, 0x0001) ; --- set the display to the selected scale percentage ; --- Return results Return SetError(@error,@extended,$iReturn) EndFunc ; end _SetWinDisplayScalePercent() ; =============================================================================================================================== Edited July 19, 2023 by Davegbuf Edited to make the post more legible. ioa747 1
alwaysbe23 Posted March 11, 2024 Posted March 11, 2024 Hi @Davegbuf, I would love to steal your script for my own use. I have a 4k monitor and when Im working alone, I like it at 150% but when Im sharing my screen on teams, I need to quickly change it to 300% for my coworkers to see it properly. (as an aside, my machine recommends 150% scale so that can be my 0 value as its the one I prefer, then I can set value1 to 300% and remove the other options from my configuration). How do I implement the script itself? I can see where I would change my settings, but not sure, where to save it and then run it from.
argumentum Posted March 12, 2024 Posted March 12, 2024 in your case, as you describe it, $iScale would be 5. For more info do read his stackoverflow link. You could also change the monitor's display resolution if the above is not working for you. ( optionally ) Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
aewald79 Posted April 2 Posted April 2 Hey there, I found a work around. So the issue you are seeing is that those values are just incrementing or decrementing the currently set values. So to get it to work consistently 100% of the time. You can set the scale value to the maximum then reduce it from there like this: #include <WinAPISys.au3> ;#sets scale to maximum value _WinAPI_SystemParametersInfo(0x009F, 8, Null, 0x0001) sleep(100) ;#setting to -3 will set the scale to 200% as the maximum is 350%, -4 will set it to 150% and so on. $iScaling=-3 _WinAPI_SystemParametersInfo(0x009F, $iScaling, Null, 0x0001) The nice thing is it happens so quickly you don't even notice if it runs or if it's already set to the correct value.
ViciousXUSMC Posted June 9 Posted June 9 Sort of a Necro Post but on topic, seemed better to pick up here with half the answer instead of starting a new thread. I just built a new computer and it keeps constantly having text size issues, and it seems to be a Windows bug related to scaling. The fix is to change one and/or both of the settings the Scaling as mentioned in this thread, but definitly for sure I have to often search for "text size" and change this value to something other than 100%, and then change it back and it fixes all my issues. Since this is one of those random MS bugs that probably nobody will ever fix, trying to just create a script that can reset these settings for me and set it to a hotkey or something. So my question is, as I have searched and had no luck. What is the SystemParameter for the Font Size? I used to use something like a registry change compare program and find what keys get changed and do my scripts that way, but you guys seem to find much better ways to make these changes, especially the ones that need a specific "trigger" to refresh without a reboot. Though I would not be supprised if I needed to close and reopen explorer.exe or something as even when making the change in the GUI it appears like it does that briefly.
ioa747 Posted June 10 Posted June 10 (edited) Thank you very much to @Davegbuf for all the useful information he provided us. my homework DPI_Scaling_Utility.au3 expandcollapse popup; https://www.autoitscript.com/forum/topic/210543-setting-windows-display-scale-percentage-on-the-fly-without-reboot-or-logout/#findComment-1543707 ;---------------------------------------------------------------------------------------- ; Title...........: DPI_Scaling_Utility.au3 ; Description.....: Setting Windows Display Scale Percentage on the Fly without Reboot or Logout ; if $Command Line argument is provided, the script runs in command-line mode to set DPI. ; else If no arguments are provided, the script runs in GUI mode. ; e.g. Run(@AutoItExe & ' /AutoIt3ExecuteScript "' & @ScriptDir & '\DPI_Scaling_Utility.au3" 100') ; AutoIt Version..: 3.3.16.1 Author: ioa747 Script Version: 1.0 ; Note............: Testet in Win10 22H2 ;---------------------------------------------------------------------------------------- #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #AutoIt3Wrapper_UseX64=y #include <WinAPISys.au3> #include <GUIConstantsEx.au3> #include <Array.au3> #include <FontConstants.au3> #include <StaticConstants.au3> ; Global array of common DPI scaling percentages supported by Windows. Global $DpiVals[12] = [100, 125, 150, 175, 200, 225, 250, 300, 350, 400, 450, 500] ; Checks if a command-line argument is provided to determine operating mode. If $CmdLine[0] = 1 Then ; If one argument is provided, the script runs in command-line mode to set DPI. _CmdLineMode() Else ; If no arguments are provided, the script runs in GUI mode. Global $g_hGUI Global $g_idRecommendedDPILabel _GUImode() EndIf ;--------------------------------------------------------------------------------------- ; command-line mode to set DPI. Func _CmdLineMode() Local $bSuccess = _SetDpiScaleFromCommandLine($CmdLine[1]) ; Call the function to set DPI. If Not $bSuccess Then _ShowCommandLineSyntaxError() ; Show syntax help if setting failed. Exit(-1) ; Exit with an error code. EndIf Exit(0) ; Exit successfully. EndFunc ;--------------------------------------------------------------------------------------- ; GUI mode, DPI Scaling Utility Func _GuiMode() ; Create the main GUI window. $g_hGUI = GUICreate("DPI Scaling Utility", 220, 300) ; Label to display status messages and results Local $idMessageLabel = GUICtrlCreateLabel("Use the buttons below to get/set DPI settings.", 20, 20, 180, 40, $SS_CENTER) GUICtrlSetFont(-1, 10) ; Label to display the detected system-recommended DPI. $g_idRecommendedDPILabel = GUICtrlCreateLabel("Recommended DPI: Calculating...", 20, 65, 180, 20, $SS_CENTER) GUICtrlSetFont(-1, 9, 700) ; Set bold for emphasis. ; Button to display the current system display scaling percentage. Local $idShowDPIButton = GUICtrlCreateButton("Show Current Display Scaling (%)", 20, 100, 180, 30) ; Label for the DPI selection combo box. GUICtrlCreateLabel("Select Target DPI (%):", 20, 150, 180, 20) ; Combo box for selecting the target DPI percentage. Local $idDPIInput = GUICtrlCreateCombo("", 70, 170, 80, 25) For $i = 0 To UBound($DpiVals) - 1 GUICtrlSetData($idDPIInput, $DpiVals[$i]) Next ; It tries to set it to the current DPI if found in the list, otherwise defaults to 100%. Local $initialCurrentDPI = _GetCurrentDPIPercentage() If _GetDpiArrayIndex($initialCurrentDPI) <> -1 Then GUICtrlSetData($idDPIInput, $initialCurrentDPI) Else GUICtrlSetData($idDPIInput, "100") EndIf ; Button Try to Set DPI. Local $idSetDPIButton = GUICtrlCreateButton("Try to Set DPI", 20, 210, 180, 30) GUISetState(@SW_SHOW) ; Calculate and display the recommended DPI _UpdateRecommendedDPI() While True Local $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE ExitLoop Case $idShowDPIButton ; "Show Current Display Scaling" button. Local $currentDPIPercentage = _GetCurrentDPIPercentage() ; Get current system DPI. If $currentDPIPercentage > 0 Then GUICtrlSetData($idMessageLabel, "Current system scaling: " & $currentDPIPercentage & "%") Else GUICtrlSetData($idMessageLabel, "Error: Could not retrieve current DPI scaling.") EndIf _UpdateRecommendedDPI() ; update the recommended DPI label. Case $idSetDPIButton ; "Try to Set DPI" button. Local $dpiToSetString = GUICtrlRead($idDPIInput) Local $dpiToSetNumber = Number($dpiToSetString) If @error = 0 Then ; Attempt to set the DPI scaling using the shared logic function. Local $bSetSuccess = _SetDpiScaleLogic($dpiToSetNumber) If $bSetSuccess Then GUICtrlSetData($idMessageLabel, "Attempted to set DPI to " & $dpiToSetNumber & "%.") _UpdateRecommendedDPI() ; Update recommended DPI after a successful setting attempt. Else GUICtrlSetData($idMessageLabel, "Failed to set DPI to " & $dpiToSetNumber & "%. See console for details.") EndIf Else GUICtrlSetData($idMessageLabel, "Error: Failed to convert selected value to a number. Value read: '" & $dpiToSetString & "'") EndIf EndSwitch WEnd EndFunc ;--------------------------------------------------------------------------------------- ; Displays the syntax usage for the command-line mode in a MsgBox. Func _ShowCommandLineSyntaxError() MsgBox(16, 'Syntax Error', _ 'Syntax:' & @CRLF & @CRLF & _ 'YourScriptName.exe [percentage_value]' & @CRLF & @CRLF & _ ' [percentage_value]: The desired display scaling percentage.' & @CRLF & _ ' Examples: "100", "125", "150", "175", "200", etc.' & @CRLF & _ ' (You can optionally include the "%" sign, e.g., "125%")' & @CRLF & @CRLF & _ ' Special Value:' & @CRLF & _ ' "0": Sets the display scale to the system''s recommended DPI.' & @CRLF & @CRLF & _ 'Example 1 - Set scale to 125% : ' & @CRLF & _ ' YourScriptName.exe 125' & @CRLF & @CRLF & _ 'Example 2 - Set scale to 150% : ' & @CRLF & _ ' YourScriptName.exe 150%' & @CRLF & @CRLF & _ 'Example 3 - Set scale to Recommended DPI : ' & @CRLF & _ ' YourScriptName.exe 0', 60) EndFunc ;--------------------------------------------------------------------------------------- ; Function to set the DPI scale when called from the command line. Func _SetDpiScaleFromCommandLine($sTargetScale) Local $iTargetPercentage ; Clean the input string (remove '%' if present) $sTargetScale = StringReplace($sTargetScale, "%", "") ; Ensuring the input is an integer string. If Not StringIsInt($sTargetScale) Then ConsoleWrite("Error: Invalid input format for target scale: '" & $sTargetScale & "'. Expected an integer." & @CRLF) Return SetError(-1, 0, False) EndIf $iTargetPercentage = Number($sTargetScale) ; Convert the validated string to a number. ; If the target argument is 0, interpret it as a request for the system's recommended DPI. If $iTargetPercentage = 0 Then Local $iRecommendedPercentage = _GetSystemRecommendedDPIPercentage() If $iRecommendedPercentage = -1 Then ConsoleWrite("Error: Cannot determine recommended DPI." & @CRLF) Return SetError(-3, 0, False) ; Error if recommended DPI cannot be found. EndIf $iTargetPercentage = $iRecommendedPercentage ; Set the target percentage to the recommended value. EndIf ; Validate if the target percentage is one of the predefined DPI scales. If _GetDpiArrayIndex($iTargetPercentage) = -1 Then ConsoleWrite("Error: Target percentage " & $iTargetPercentage & "% is not a valid predefined DPI scale." & @CRLF) Return SetError(-2, 0, False) EndIf Return _SetDpiScaleLogic($iTargetPercentage) ; Call the shared core logic to set DPI. EndFunc ;--------------------------------------------------------------------------------------- ; --- Shared Core DPI Setting Logic --- ; function to calculates the correct relative index needed by the Windows API ; based on the system's detected "recommended" DPI and the desired target percentage. Func _SetDpiScaleLogic($percentScaleToSet) ; First, determine the system's recommended DPI percentage. Local $iRecommendedPercentage = _GetSystemRecommendedDPIPercentage() If $iRecommendedPercentage = -1 Then ConsoleWrite("Error: Cannot determine recommended DPI to set scaling relatively." & @CRLF) Return SetError(-6, 0, False) ; Error if recommended DPI cannot be found. EndIf ; Get the absolute array indices for the recommended and target DPIs from $DpiVals. Local $iRecommendedAbsIndex = _GetDpiArrayIndex($iRecommendedPercentage) Local $iTargetAbsIndex = _GetDpiArrayIndex($percentScaleToSet) ; Validate that both recommended and target DPIs are found in our predefined list. If $iRecommendedAbsIndex = -1 Then ConsoleWrite("Error: Recommended DPI (" & $iRecommendedPercentage & "%) not found in predefined list ($DpiVals)." & @CRLF) Return SetError(-7, 0, False) EndIf If $iTargetAbsIndex = -1 Then ConsoleWrite("Error: Target DPI (" & $percentScaleToSet & "%) not found in predefined list ($DpiVals)." & @CRLF) Return SetError(-8, 0, False) EndIf ; Calculate the relative index to pass to SystemParametersInfo. ; This is the crucial part based on the empirical observation that ; the API uses a relative step from the recommended DPI. Local $iFinalRelativeIndexToPass = $iTargetAbsIndex - $iRecommendedAbsIndex ; Log the parameters being used for the DPI setting attempt. ConsoleWrite("Attempting to set DPI:" & @CRLF & _ " Target Percentage: " & $percentScaleToSet & "%" & @CRLF & _ " Recommended Percentage: " & $iRecommendedPercentage & "%" & @CRLF & _ " Relative Index to Pass to API: " & $iFinalRelativeIndexToPass & @CRLF) ; Perform the actual Windows API call to set the display scaling. ; 0x009F corresponds to SPI_SETLOGICALDPIOVERRIDE (or SPI_SETLOGICALDPIAWARENESS). ; 0x0001 (SPIF_UPDATEINIFILE) ensures the setting is written to the user profile, making it persistent. Local $bSuccess = _WinAPI_SystemParametersInfo(0x009F, $iFinalRelativeIndexToPass, Null, 0x0001) ; Log API call failure if it occurs. If Not $bSuccess Then ConsoleWrite("API call _WinAPI_SystemParametersInfo(0x009F, " & $iFinalRelativeIndexToPass & ", ...) failed. @error=" & @error & ", @extended=" & @extended & @CRLF) EndIf Return SetError(@error, @extended, $bSuccess) ; Return success/failure status. EndFunc ;--------------------------------------------------------------------------------------- ; Function to find the array index of a given DPI percentage within the $DpiVals array. ; Returns -1 if the percentage is not found. Func _GetDpiArrayIndex($percentage) Return _ArraySearch($DpiVals, $percentage) EndFunc ;--------------------------------------------------------------------------------------- ; Function to get the current system-wide DPI in pixels per inch. ; (e.g., 96 for 100% scaling, 120 for 125% scaling). Func _GetCurrentSystemDPI() Local $hDC = _WinAPI_GetDC(0) ; Get device context for the entire screen (desktop). If $hDC = 0 Then ConsoleWrite("Error: _GetCurrentSystemDPI failed to get DC." & @CRLF) Return -1 ; Return -1 on error if DC cannot be obtained. EndIf ; LOGPIXELSX (88) retrieves the number of pixels per logical inch along the screen width. Local $iLogicalDPI = _WinAPI_GetDeviceCaps($hDC, $LOGPIXELSX) _WinAPI_ReleaseDC(0, $hDC) ; Release the device context to free up resources. Return $iLogicalDPI EndFunc ;--------------------------------------------------------------------------------------- ; Function to get the current display scaling percentage. ; Assumes that 96 DPI equals 100% scaling, which is the standard baseline for Windows. Func _GetCurrentDPIPercentage() Local $currentDPI = _GetCurrentSystemDPI() If $currentDPI = -1 Then Return -1 ; Error if DPI could not be retrieved by _GetCurrentSystemDPI. EndIf ; Calculate the percentage: (CurrentDPI / 96) * 100. Return Round(($currentDPI / 96) * 100) EndFunc ;--------------------------------------------------------------------------------------- ; Function to get the current relative DPI index (0 for recommended, 1 for next step up, etc.). ; This directly queries the value that corresponds to the second parameter of SPI_SETLOGICALDPIOVERRIDE. Func _GetRelativeCurrentDPIIndex() Local $relativeDPIIndex = 0 ; This variable will hold the relative index (0, 1, -1, etc.). ; SPI_GETLOGICALDPIAWARENESS (0x009F) when used to GET (uiParam=0), reads the current relative index into pvParam. Local $retval = _WinAPI_SystemParametersInfo(0x009F, 0, $relativeDPIIndex, 0) If $retval Then Return $relativeDPIIndex Else ConsoleWrite("Error: _GetRelativeCurrentDPIIndex failed to retrieve value. Return value: " & $retval & @CRLF) Return -9999 ; Sentinel value for error. EndIf EndFunc ;--------------------------------------------------------------------------------------- ; Function to determine the OS's recommended DPI percentage for the current display. ; This calculates the absolute percentage that corresponds to the relative index 0. Func _GetSystemRecommendedDPIPercentage() Local $currentActualPercentage = _GetCurrentDPIPercentage() If $currentActualPercentage = -1 Then Return -1 ; Return error if current percentage cannot be obtained. Local $currentRelativeIndex = _GetRelativeCurrentDPIIndex() If $currentRelativeIndex = -9999 Then Return -1 ; Return error if relative index cannot be obtained. Local $currentAbsIndexInArray = _GetDpiArrayIndex($currentActualPercentage) If $currentAbsIndexInArray = -1 Then ConsoleWrite("Warning: Current DPI percentage (" & $currentActualPercentage & "%) not found in DpiVals array. Cannot reliably determine recommended DPI." & @CRLF) ; If the current actual percentage isn't in our predefined list, we can't reliably calculate the recommended one. Return -1 EndIf ; The index of the recommended DPI in our array is the current absolute index ; minus the current relative index. Local $recommendedAbsIndexInArray = $currentAbsIndexInArray - $currentRelativeIndex ; Ensure the calculated index is within the valid bounds of the $DpiVals array. If $recommendedAbsIndexInArray < 0 Or $recommendedAbsIndexInArray >= UBound($DpiVals) Then ConsoleWrite("Error: Calculated recommended DPI index (" & $recommendedAbsIndexInArray & ") is out of bounds for DpiVals array. Cannot determine recommended DPI. This might mean the current DPI is not a standard step." & @CRLF) Return -1 EndIf Return $DpiVals[$recommendedAbsIndexInArray] ; Return the recommended DPI percentage. EndFunc ;--------------------------------------------------------------------------------------- ; function to update the recommended DPI label on the GUI. Func _UpdateRecommendedDPI() ; Only update GUI controls if the GUI window has been successfully created. If IsHWnd($g_hGUI) Then Local $recommendedDPI = _GetSystemRecommendedDPIPercentage() If $recommendedDPI > 0 Then GUICtrlSetData($g_idRecommendedDPILabel, "Recommended DPI: " & $recommendedDPI & "%") Else GUICtrlSetData($g_idRecommendedDPILabel, "Recommended DPI: N/A (Error or not in list)") EndIf EndIf EndFunc ;--------------------------------------------------------------------------------------- Added: if $CmdLine argument is provided, the script runs in command-line mode to set DPI. else If no $CmdLine arguments are provided, the script runs in GUI mode. ; e.g. Run(@AutoItExe & ' /AutoIt3ExecuteScript "' & @ScriptDir & '\DPI_Scaling_Utility.au3" 100') If the $CmdLine argument is Special Value: "0" then sets the display scale to the system''s recommended DPI. Edit: Add more info with the power of SciTE AI Assistant Edited June 10 by ioa747 Add Special Value: "0" argumentum 1 I know that I know nothing
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