It all seems to be working fine, and is quite fun to experiment with. I mainly had in mind to check if a window appears on a certain monitor.

Do notify of any errors, this is the sort of script where an error can easily be made.

Btw try to work out how you might write such a script, before you look at the code, the logic is quite interesting. Maybe even take a few hours or a few days.

Code: Select all

```
q:: ;check if windows overlap
vOpt := ""
;vOpt .= "r" ;XYRB coordinates 'RECT style'
;vOpt .= "c" ;win 1 contains win 2
;vOpt .= "e" ;win 1 = win 2
;vOpt .= "w" ;win 1 is within win 2 (win 2 contains win 1)
WinGetPos, vPosX1, vPosY1, vPosW1, vPosH1, ahk_class Notepad
WinGetPos, vPosX2, vPosY2, vPosW2, vPosH2, ahk_class WordPadClass
MsgBox, % JEE_RectOverlapsRect(vPosX1, vPosY1, vPosW1, vPosH1, vPosX2, vPosY2, vPosW2, vPosH2, vOpt)
return
;==================================================
JEE_RectOverlapsRect(vX1, vY1, vW1, vH1, vX2, vY2, vW2, vH2, vOpt="")
{
;if (A is left of B) [rightmost A is left of leftmost B]
;|| (A is right of B) [leftmost A is right of righttmost B]
;|| (A is is above B) [bottom of A is is above top of B]
;|| (A is is below B) [top of A is is below bottom of B]
;then A and B do not overlap
if InStr(vOpt, "x") ;reduce width and height values by 1
vW1 -= 1, vH1 -= 1, vW2 -= 1, vH2 -= 1
if InStr(vOpt, "e") ;(A = B) A equals B
if !(vX1 = vX2) || !(vY1 = vY2) || !(vW1 = vW2) || !(vH1 = vH2)
return 0
else
return 1
if InStr(vOpt, "r") ;coordinates are XYRB 'RECT style'
vR1 := vW1, vB1 := vH1, vR2 := vW2, vB2 := vH2
else
vR1 := vX1+vW1, vB1 := vY1+vH1, vR2 := vX2+vW2, vB2 := vY2+vH2
if InStr(vOpt, "c") ;(A contains B) A contains all of or is equal to B
if (vX2 < vX1) || (vY2 < vY1) || (vR2 > vR1) || (vH2 > vH1)
return 0
else
return 1
if InStr(vOpt, "w") ;(A within B) A is within or is equal to B
if (vX1 < vX2) || (vY1 < vY2) || (vR1 > vR2) || (vH1 > vH2)
return 0
else
return 1
;(A overlaps B)
if (vR1 < vX2) || (vX1 > vR2) || (vB1 < vY2) || (vY1 > vB2)
return 0
else
return 1
}
```

c++ - Determine if two rectangles overlap each other? - Stack Overflow

http://stackoverflow.com/questions/3063 ... each-other

[EDIT:][regarding monitors there are in fact functions such as MonitorFromWindow]

Close all windows/programs except what is on Monitor 2? - AutoHotkey Community

https://autohotkey.com/boards/viewtopic ... 60#p143960