72 lines · 2.2 KB
Raw Download
1
#Requires AutoHotkey v2.0
2
3
; Get the active window
4
activeWindow := WinExist("A")
5
if !activeWindow {
6
    MsgBox("No active window found!")
7
    ExitApp
8
}
9
10
; Get window position and dimensions
11
WinGetPos(&wLeft, &wTop, &wWidth, &wHeight, activeWindow)
12
13
; Find the correct monitor by checking each monitor's bounds
14
windowCenterX := wLeft + wWidth/2
15
windowCenterY := wTop + wHeight/2
16
monitorCount := MonitorGetCount()
17
currentMonitor := 1
18
19
Loop monitorCount {
20
    MonitorGet(A_Index, &mLeft, &mTop, &mRight, &mBottom)
21
    if (windowCenterX >= mLeft && windowCenterX <= mRight && 
22
        windowCenterY >= mTop && windowCenterY <= mBottom) {
23
        currentMonitor := A_Index
24
        break
25
    }
26
}
27
28
; Get the work area of the correct monitor
29
MonitorGetWorkArea(currentMonitor, &mLeft, &mTop, &mRight, &mBottom)
30
31
; Calculate monitor dimensions
32
monitorWidth := mRight - mLeft
33
monitorHeight := mBottom - mTop
34
35
; Create GUI for scale selection
36
MyGui := Gui(, "Scale Active Window")
37
MyGui.Add("Text",, "Select window scale (percentage of screen):")
38
scaleDropdown := MyGui.Add("DropDownList", "Choose3", ["100", "90", "80", "70", "60", "50"])  ; Choose3 sets default to 80%
39
MyGui.Add("Button", "default", "Scale").OnEvent("Click", ScaleWindow)
40
MyGui.OnEvent("Close", ScaleWindow)
41
MyGui.Show()
42
43
ScaleWindow(*) {
44
    global activeWindow, monitorWidth, monitorHeight, mLeft, mTop, scaleDropdown
45
    
46
    ; Get selected scale
47
    selectedScale := Number(scaleDropdown.Text) / 100
48
    
49
    ; Calculate new dimensions maintaining 16:9 aspect ratio
50
    if (monitorWidth / monitorHeight > 16/9) {
51
        ; Monitor is wider than 16:9
52
        newHeight := monitorHeight * selectedScale
53
        newWidth := newHeight * 16/9
54
    } else {
55
        ; Monitor is taller than 16:9
56
        newWidth := monitorWidth * selectedScale
57
        newHeight := newWidth * 9/16
58
    }
59
    
60
    ; Calculate center position
61
    newLeft := mLeft + (monitorWidth - newWidth) / 2
62
    newTop := mTop + (monitorHeight - newHeight) / 2
63
    
64
    ; Move and resize window
65
    WinMove(newLeft, newTop, newWidth, newHeight, activeWindow)
66
    
67
    ; Close GUI after applying
68
    MyGui.Destroy()
69
}
70
71
; Clean up when script exits
72
MyGui.OnEvent("Close", (*) => ExitApp())