#singleinstance force #persistent #noenv #warn #keyhistory 0 ;; Run as adminstrator. if(!a_isadmin){ try if(a_iscompiled) run *runas "%a_scriptfullpath%" /restart else run *runas "%a_ahkpath%" /restart "%a_scriptfullpath%" exitapp } ;; Standard setup. sendmode input setworkingdir %a_scriptdir% ;; Performance improvements. listlines off ;process priority,, a setbatchlines -1 ;; Configure menu. menu tray, tip, Scale menu tray, nostandard menu tray, icon, shell32.dll, 141 menu tray, add, &Edit, buttonedit menu tray, add, &Restart, buttonrestart menu tray, add, E&xit, buttonexit ;; Register shell hook. gui +lastfound dllcall("RegisterShellHookWindow", uint, winexist()) msg := dllcall("RegisterWindowMessage", str, "SHELLHOOK") onmessage(msg, "open") scale := 1 ; Current scale. windows := {} ; Current tracked windows. return ;; Handle menu button presses. buttonedit: edit return buttonrestart: reload return buttonexit: exitapp ;; Handle scrolling when cursor is over desktop. #if atdesktop() mbutton::scale(1.0) +wheelup::scale(scale+0.4) +wheeldown::scale(scale-0.4) wheelup::scale(scale+0.1) wheeldown::scale(scale-0.1) #if ;; Handle Alt-F4 when scale is not 100%. #if scale != 1.0 !F4:: scale1(1.0, winactive("a")) windows.delete(winactive("a")) send !{F4} return #if ;; Is cursor over desktop? atdesktop(){ mousegetpos,,, hwnd wingetclass class, ahk_id %hwnd% return class == "Progman" || class == "WorkerW" } ;; Zoom all windows to scale s. scale(s){ global scale global windows if(s < 0.1) s := 0.1 if(s > 1.0) s := 1.0 detecthiddenwindows off winget w, list loop % w { hwnd := w%a_index% scale1(s, hwnd) } ;; Untrack windows when scale is reset to 100%. if(s == 1.0) windows := {} scale := s } ;; Zoom window to scale s. scale1(s, hwnd){ global scale global windows static WS_BORDER := 0x800000 ;; Ignore windows without title bar. winget style, style, ahk_id %hwnd% if(style & WS_BORDER == 0) return ;; Enable/disable window close controls. if(s == 1.0) enable(hwnd) else disable(hwnd) winreallygetpos(hwnd, x1, y1, w1, h1) ;; Save window's original width, height. neww := false if(!windows.haskey(hwnd)){ windows[hwnd] := [w1, h1] neww := true } ;; Calculate new width, height, x, y. w0 := windows[hwnd][1], h0 := windows[hwnd][2] w1 := w0*(neww? 1: scale), h1 := h0*(neww? 1: scale) w2 := w0*s, h2 := h0*s x2 := round(x1+(w1-w2)/2), y2 := round(y1+(h1-h2)/2) ;; Zoom window. winreallymove(hwnd, x2, y2, w2, h2) } ;; Disable window close controls. disable(hwnd){ menu := dllcall("user32\GetSystemMenu", uint, hwnd, uint, 0) dllcall("user32\DeleteMenu", uint, menu, uint, 0xf060, uint, 0x0) } ;; Enable window close controls. enable(hwnd){ menu := dllcall("user32\GetSystemMenu", uint, hwnd, uint, 1) dllcall("user32\DrawMenuBar", uint, hwnd) } ;; Set scale for new windows. open(wparam, lparam){ global scale static HSHELL_WINDOWCREATED := 1 if(wparam == HSHELL_WINDOWCREATED) scale1(scale, lparam) } ;; Get position of any window, even a minimized one. winreallygetpos(hwnd, byref x, byref y, byref w="", byref h="") { varsetcapacity(wp, 44), numput(44, wp) dllcall("GetWindowPlacement", uint, hwnd, uint, &wp) x := numget(wp, 28, "int") y := numget(wp, 32, "int") w := numget(wp, 36, "int") - x h := numget(wp, 40, "int") - y } ;; Set position of any window, even a minimized one. winreallymove(hwnd, x, y, w, h) { varsetcapacity(wp, 44, 0), numput(44, wp, "uint") numput(5, wp, 8, "uint") numput(x, wp, 28, "int") numput(y, wp, 32, "int") numput(w + x, wp, 36, "int") numput(h + y, wp, 40, "int") dllcall("SetWindowPlacement", ptr, hwnd, ptr, &wp) }