Code: Select all
#SingleInstance, Force
OnMessage(0x201, "WM_LBUTTONDOWN")
Gui, 1: New, -Caption hWndhGUI1
Gui, Margin, 0, 0
Gui, Add, Text, w100 h100 Border, Drag to move
Gui, Show, x500
Gui, 2: New, -Caption hWndhGUI2
Gui, Margin, 0, 0
Gui, Add, Text, w100 h100 Border, Will move too
Gui, Show, x725
Esc:: ExitApp
;-------------------------------------------------------------------------------
WM_LBUTTONDOWN() { ; moves two windows
;-------------------------------------------------------------------------------
global hGUI1, hGUI2
IfNotEqual, A_Gui, 1, Return
Prev_CoordModeMouse := A_CoordModeMouse
CoordMode, Mouse, Screen
MouseGetPos, old_Mx, old_My
WinGetPos, old_Wx, old_Wy
While GetKeyState("LButton") {
MouseGetPos, now_Mx, now_My
x := old_Wx + now_Mx - old_Mx
, y := old_Wy + now_My - old_My
, old_Mx := now_Mx, old_Wx := x
, old_My := now_My, old_Wy := y
hDWP := DllCall("BeginDeferWindowPos", "Int", 2) ; 2 windows
If hDWP {
hDWP := DllCall("DeferWindowPos"
, "Uint", hDWP, "UInt", hGUI1, "UInt", 0
, "Int", x, "Int", y, "Int", 100, "Int", 100
, "UInt", 0x0214)
}
If hDWP {
hDWP := DllCall("DeferWindowPos"
, "Uint", hDWP, "UInt", hGUI2, "UInt", 0
, "Int", x + 225, "Int", y, "Int", 100, "Int", 100
, "UInt", 0x0214)
}
DllCall("EndDeferWindowPos", "UInt", hDWP)
}
CoordMode, Mouse, %Prev_CoordModeMouse% ; restore
}