diff options
Diffstat (limited to 'drm.ahk')
-rw-r--r-- | drm.ahk | 55 |
1 files changed, 44 insertions, 11 deletions
@@ -65,18 +65,35 @@ Configure() SelectMenuResolution(ItemName, ItemPos, MenuName) { - ResArray := StrSplit(ItemName, "x") - SwitchToResolutionFrom(ResArray[1], ResArray[2], A_ScreenWidth, A_ScreenHeight) + w := 0 + h := 0 + r := 0 + for k, v in StrSplit(ItemName, " ") + { + if (k = 1) + { + a := StrSplit(v, "x") + w := a[1] + h := a[2] + } + else if ("Hz" = SubStr(v, StrLen(v) - 1)) + r := SubStr(v, 1, StrLen(v) - 2) + } + if (w = 0 or h = 0) + MsgBox, Invalid width or height + new := {width: w, height: h, rate: r, depth: 32} + old := Get() + SwitchResolution(new, old) } ; Save window positions, switch to given resolution, restore window positions -SwitchToResolutionFrom(WidthNew, HeightNew, WidthOrig, HeightOrig) +SwitchResolution(new, old) { Positions := {} Save(Positions) - SetResolution(WidthNew, HeightNew) + Set(new) Sleep, 500 Restore(Positions) @@ -86,7 +103,7 @@ SwitchToResolutionFrom(WidthNew, HeightNew, WidthOrig, HeightOrig) if (ErrorLevel = 1) ; user didn't press escape return - SetResolution(%WidthOrig%, %HeightOrig%) + Set(old) Sleep, 500 Restore(Positions) } @@ -183,18 +200,34 @@ Restore(Positions) ; Set screen resolution -SetResolution(Width, Height, ColorDepth := 32) +Set(res) { VarSetCapacity(DeviceMode, 156, 0) - NumPut(156, DeviceMode, 36) + NumPut(156, DeviceMode, 36) DllCall("EnumDisplaySettingsA", UInt, 0, UInt, -1, UInt, &DeviceMode) - NumPut(0x5c0000, DeviceMode, 40) - NumPut(ColorDepth, DeviceMode, 104) - NumPut(Width, DeviceMode, 108) - NumPut(Height, DeviceMode, 112) + NumPut(0x5c0000, DeviceMode, 40) + NumPut(res.depth, DeviceMode, 104) + NumPut(res.width, DeviceMode, 108) + NumPut(res.height, DeviceMode, 112) + if (res.rate > 0) + NumPut(res.rate, DeviceMode, 120) DllCall("ChangeDisplaySettingsA", UInt, &DeviceMode, UInt, 0) } +; Get screen resolution + +Get() +{ + VarSetCapacity(DeviceMode, 156, 0) + NumPut(156, DeviceMode, 36) + DllCall("EnumDisplaySettingsA", UInt, 0, UInt, -1, UInt, &DeviceMode) + w := NumGet(&DeviceMode, 108, "uint4") + h := NumGet(&DeviceMode, 112, "uint4") + d := NumGet(&DeviceMode, 104, "uint4") + r := NumGet(&DeviceMode, 120, "uint4") + return {width: w, height: h, depth: d, rate: r} +} + ; Get position of any window, even a minimized one WinReallyGetPos(hwnd, ByRef x, ByRef y, ByRef w="", ByRef h="") |