Example scripts and tips (replaces Old Scripts & Tips archive)
Moderators: Dorian (MJT support), JRL, Phil Pendlebury
-
Dorian (MJT support)
- Automation Wizard
- Posts: 1384
- Joined: Sun Nov 03, 2002 3:19 am
-
Contact:
Post
by Dorian (MJT support) » Thu Dec 10, 2020 3:05 pm
Tested in Windows 10.
I was asked how to do this today, and thought it might be useful to someone. This snippet returns a result code for the given scale/zoom percentage.
For example, mine is set to 250%, and Result is returned as 240.
Code: Select all
LibFunc>User32,GetDC,hDC,0
LibFunc>GDI32,GetDeviceCaps,Result,hDC,88
messagemodal>Result
96 – Smaller 100%
120 – Medium 125%
144 – Larger 150%
192 – Extra Large 200%
240 – Custom 250%
288 – Custom 300%
384 – Custom 400%
480 – Custom 500%
Yes, we have a
Custom Scripting Service. Message me or go
here
-
Phil Pendlebury
- Automation Wizard
- Posts: 543
- Joined: Tue Jan 16, 2007 9:00 am
-
Contact:
Post
by Phil Pendlebury » Sat May 21, 2022 7:31 am
Additionally if we want to find the actual percentage scale factor and then do some stuff with it.:
Code: Select all
// 96 – Smaller 100%
// 120 – Medium 125%
// 144 – Larger 150%
// 192 – Extra Large 200%
// 240 – Custom 250%
// 288 – Custom 300%
// 384 – Custom 400%
// 480 – Custom 500%
LibFunc>User32,GetDC,hDC,0
LibFunc>GDI32,GetDeviceCaps,Result,hDC,88
// Test (300% Scaled)
Let>Result=288
Let>ResBy96=Result/96
Let>ResPerc=ResBy96*100
messagemodal>%ResPerc% is the scaling factor
// So if a box is 50x60
// and you ned to scale it
Let>xboxdim=50
Let>yboxdim=60
//
Let>xboxdimx=xboxdim/100
Let>xboxdimx=xboxdimx*ResPerc
Let>yboxdimy=yboxdim/100
Let>yboxdimy=yboxdimy*ResPerc
MDL>Original x: %xboxdim% will now be: %xboxdimx%%CRLF%Original y: %yboxdim% will now be: %yboxdimy%
-
Grovkillen
- Automation Wizard
- Posts: 1131
- Joined: Fri Aug 10, 2012 2:38 pm
- Location: Bräcke, Sweden
-
Contact:
Post
by Grovkillen » Sun Feb 25, 2024 8:03 pm
This is what I do with all my scripts now. First I do a check and see what maximum vertical pixel count the desktop uses and then I get the highest dpi value. I compare these to my (for now) standard size of 1080 vs 96. I scale from those values if needed:
Code: Select all
Let>SCALE_OF_DIALOG=100
Let>DECIMAL_SEPARATOR=.
Let>RP_WINDOWMODE=0
Let>RP_CAPTURESTDOUT=1
Let>POWERSHELL_COMMAND=Get-WmiObject win32_desktopmonitor | ConvertTo-Json
RunProgram>cmd /c chcp 65001 > nul & cmd /c PowerShell -Command " & {%POWERSHELL_COMMAND%}"
Let>RP_WINDOWMODE=1
Let>RP_CAPTURESTDOUT=0
Trim>RP_STDOUT,TEMP_string
JSONParse>TEMP_string,$.DeviceID,TEMP_device_id
If>TEMP_device_id_count=0
JSONParse>TEMP_string,$[*].DeviceID,TEMP_device_id
JSONParse>TEMP_string,$[*].ScreenHeight,TEMP_y_resolution
JSONParse>TEMP_string,$[*].PixelsPerYLogicalInch,TEMP_y_ppi
Else>
JSONParse>TEMP_string,$.ScreenHeight,TEMP_y_resolution
JSONParse>TEMP_string,$.PixelsPerYLogicalInch,TEMP_y_ppi
Endif>
If>TEMP_device_id_count>0
Let>MAX_VERTICAL_RESOLUTION=0
Let>MAX_VERTICAL_PIXEL_PER_INCH=0
Let>k=0
Repeat>k
Let>k=k+1
Let>TEMP_resolution=TEMP_y_resolution_%k%
Let>TEMP_check=TEMP_resolution*0
If>{(%TEMP_resolution% > %MAX_VERTICAL_RESOLUTION%) AND (%TEMP_check% = 0)}
Let>MAX_VERTICAL_RESOLUTION=TEMP_resolution
Endif>
Let>TEMP_pixel_per_inch=TEMP_y_ppi_%k%
Let>TEMP_check=TEMP_pixel_per_inch*0
If>{(%TEMP_pixel_per_inch% > %MAX_VERTICAL_PIXEL_PER_INCH%) AND (%TEMP_check% = 0)}
Let>MAX_VERTICAL_PIXEL_PER_INCH=TEMP_pixel_per_inch
Endif>
Until>k=TEMP_device_id_count
Let>SCREEN_DENSITY={(%MAX_VERTICAL_RESOLUTION%/1080*%MAX_VERTICAL_PIXEL_PER_INCH%/96)}
Else>
Let>SCREEN_DENSITY=1
Endif>
Let>SCALE_OF_DIALOG={Round(%SCALE_OF_DIALOG%*%SCREEN_DENSITY%)}
Let>MSG_HEIGHT={Round(350*%SCALE_OF_DIALOG%/100)}
Let>MSG_WIDTH={Round(300*%SCALE_OF_DIALOG%/100)}
The SCALE_OF_DIALOG parameter is used in case I want to tweak the dialog size (may it be user preference or my own use case).