I've had a go at a script for this. There are likely other good/better approaches, so I would welcome other people sharing scripts.
Code: Select all
;if the main window is moved, any 'child' windows that overlap with it, are also moved
Gui, 99: +Resize +hwndhWnd1
Gui, 99: Show, w800 h600
Gui, 1: +Resize +hwndhWnd2 +AlwaysOnTop
Gui, 1: Show, x5 y5 w200 h200, Child #1
Gui, 2: +Resize +hwndhWnd3 +AlwaysOnTop
Gui, 2: Show, x215 y5 w200 h200, Child #2
WinGetPos, vWin1X, vWin1Y, vWin1W, vWin1H, % "ahk_id " hWnd1
WinGetPos, vWin2X, vWin2Y, vWin2W, vWin2H, % "ahk_id " hWnd2
WinGetPos, vWin3X, vWin3Y, vWin3W, vWin3H, % "ahk_id " hWnd3
vOverlap1 := JEE_WinOverlap(hWnd1, hWnd2)
vOverlap2 := JEE_WinOverlap(hWnd1, hWnd3)
return
;==================================================
JEE_WinOverlap(hWnd1, hWnd2)
{
local RECT1, RECT2, RECT3
VarSetCapacity(RECT1, 16, 0)
VarSetCapacity(RECT2, 16, 0)
VarSetCapacity(RECT3, 16, 0)
DllCall("user32\GetWindowRect", Ptr,hWnd1, Ptr,&RECT1)
DllCall("user32\GetWindowRect", Ptr,hWnd2, Ptr,&RECT2)
return DllCall("user32\IntersectRect", Ptr,&RECT3, Ptr,&RECT1, Ptr,&RECT2)
}
;==================================================
onMove(hWinEventHook, event, hWnd)
{
global
DetectHiddenWindows, On
;EVENT_SYSTEM_MOVESIZEEND := 0xB
static _ := DllCall("SetWinEventHook", Int,0xB, Int,0xB, Int,0, Ptr,RegisterCallback("onMove"), Int,0, Int,0, Int,0)
vWin1OldX := vWin1X, vWin1OldY := vWin1Y
vWin2OldX := vWin2X, vWin2OldY := vWin2Y
vWin3OldX := vWin3X, vWin3OldY := vWin3Y
WinGetPos, vWin1X, vWin1Y, vWin1W, vWin1H, % "ahk_id " hWnd1
WinGetPos, vWin2X, vWin2Y, vWin2W, vWin2H, % "ahk_id " hWnd2
WinGetPos, vWin3X, vWin3Y, vWin3W, vWin3H, % "ahk_id " hWnd3
if !WinActive("ahk_id " hWnd1)
return
if vOverlap1
{
vWin2X := vWin1X+vWin2OldX-vWin1OldX
vWin2Y := vWin1Y+vWin2OldY-vWin1OldY
WinMove, % "ahk_id " hWnd2,, % vWin2X, % vWin2Y
}
if vOverlap2
{
vWin3X := vWin1X+vWin3OldX-vWin1OldX
vWin3Y := vWin1Y+vWin3OldY-vWin1OldY
WinMove, % "ahk_id " hWnd3,, % vWin3X, % vWin3Y
}
vOverlap1 := JEE_WinOverlap(hWnd1, hWnd2)
vOverlap2 := JEE_WinOverlap(hWnd1, hWnd3)
}
;==================================================
[EDIT:] Btw is there not some built-in GuiMove subroutine (cf. GuiSize)?