-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path_WinArrange.ahk
36 lines (29 loc) · 1.6 KB
/
_WinArrange.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
; Original from: https://autohotkey.com/board/topic/80580-how-to-programmatically-tile-cascade-windows/
; phazei: I updated it to use non-deprecated calls.
; Also, not sure if it's a Win11 thing or not, but the "size" param for aKids needed adjusting.
; It might be because window id's in the array are 0x123abc vs the 0-1920 for the screen rectangle.
; But I have no idea what that "fill" line is for other than being some bitwise thing
WinArrange(tileOrCascade := 1, windowHandles := [], arrangeType := 0x1, clientArea := [], mainWindow := 0x0) {
; Prepare the client area if provided
areaPointer := clientArea ? BufferFromArray(clientArea, "Int") : 0
; Prepare the window handles
windowsPointer := windowHandles ? BufferFromArray(windowHandles, "Ptr") : 0
; Call the respective DLL function based on tileOrCascade
if (tileOrCascade = 1) { ; Tile windows
return DllCall("TileWindows", "Int", mainWindow, "UInt", arrangeType, "Ptr", areaPointer, "Int", windowHandles.Length, "Ptr", windowsPointer)
} else { ; Cascade windows
if arrangeType != 4 ; If arrangeType is 4, windows will be cascaded in ZORDER
arrangeType := 0
return DllCall("CascadeWindows", "Int", mainWindow, "UInt", arrangeType, "Ptr", areaPointer, "Int", windowHandles.Length, "Ptr", windowsPointer)
}
}
BufferFromArray(arr, type) {
elemSize := type = "Int" ? 4 : A_PtrSize
totalSize := arr.Length * elemSize
buf := Buffer(totalSize)
for i, val in arr {
offset := (i - 1) * elemSize
NumPut(type, val, buf, offset)
}
return buf
}