Here is what I have:
Code: Select all
win_snapToMonitor(winTitle := "a", subCommand := ""){
static history := []
hwnd := winExist(winTitle)
monNo := coord_OnMonitor(hwnd) ;this function simply return a monitor No, such as "1" or "2"
SysGet, mon, Monitor,% monNo
WinGetPos, winX, winY, winW, winH,% winTitle
;if (history has hwnd in it){ ;this block is pseudo code
; restore window
; remove it from the "history" array
; return
;}
;else{
; history.push(hwnd:{x:winX, y:winY, w:winW, h:winH})
;}
if (subCommand = "toLeft")
WinMove,% "ahk_id" hwnd,,% monLeft ;snap to left corner of monitor
else if (subCommand = "toTop") ;snap to top corner of monitor
WinMove,% "ahk_id" hwnd,,,% monTop
else if (subCommand = "toRight")
winMove,% "ahk_id" hwnd,,,% monTop
else if (subCommand = "toBottom")
winMove,% "ahk_id" hwnd,,,% monBottom - winW
else if (subCommand = "Horiz")
winMove,% "ahk_id" hwnd,,% monLeft,,% monRight ;fill all horizontal
else if (subCommand = "Vert")
WinMove,% "ahk_id" hwnd,,,% monTop,,% (montop - monBottom) * -1 ;fill all vertical
}
I am trying to store a dictionary (map?) whose name is a window handle. Looking at it on its own, it looks like this
Code: Select all
hwnd := winExist("code")
WinGetPos, winX, winY, winW, winH,% winTitle
history := []
history.push(hwnd{x:winX, y:winY, w:winW, h:winH})
history.push(%hwnd%:{x:winX, y:winY, w:winW, h:winH}) ;this does not work either
history.push((%hwnd%):{x:winX, y:winY, w:winW, h:winH}) ;this does not work either
history.push((hwnd):{x:winX, y:winY, w:winW, h:winH}) ;this does not work either
msgbox,% json.dump(history) ;print a strinfied json of the AHK object
Code: Select all
[
"0x13f11" : {
"x" : 100,
"y" : 100,
"w" : 1000,
"w" : 1000,
}
"0x13f722" : {
"x" : 200,
"y" : 200,
"w" : 2000,
"w" : 2000,
}
...
]
The code for arrayMatch
Code: Select all
;Match a value in a array using case-insensitive string matching, with the option to return first or all matches and value or index
arrayMatch(array, match, all := 0, index := 0){
out := []
loop,% array.Length()
{
if (index){
if (array[A_Index] = match){
return A_Index
}
}
else{
if (array[A_Index] == match){
if (all)
out.push((array[A_Index]))
else
return (array[A_Index])
}
}
}
return out
}
PS: I know windows kind of does this feature, but this is a programming project for me.
Any help would be greatly appreciated!