Thank you for providing this function.
It solved a problem I had no solution for until I find this. My problem was that when I use always-on-top Gui overlays to add-on a main Gui window, if you drag the main window the overlays will stay in their place and it looks really stupid
So yes this is a good solution thank you.
While implementing it in my script, discovered that if I dragged any other window related to my script, all the window in handles list would move even if I am not dragging any of them.
So I have added these two lines which solved this issue for me.
Edit: Disclaimer. I was using first post version and have not tested the most recent one yet (2019-03-19). Most recent is found on page 1 after a few posts.
Just wanted to let you know whiloe also saying thanks.
Code: Select all
;-----------------------------------------------------------------------------------------------------------------------------------------
MoveTogether(wParam, lParam, _, hWnd) { ; using DeferWindowPos
;-----------------------------------------------------------------------------------------------------------------------------------------
; https://www.autohotkey.com/boards/viewtopic.php?t=43192 by Wolf_II
;static init := OnMessage(0x0A1, "MoveTogether") ; WM_NCLBUTTONDOWN
global MoveTogetherHandles := [hGuiMain, hGuiGdipOverlay, hlv_Tx, hLB2_type]
; Here ---
if (hWnd != MoveTogetherHandles[1]) ; MainWindow is assumed to be key #1 in Handles Object
return ; Do not execute if we are dragging another window than the Main Window
; --End
;---------------------------------------------
CoordMode, Mouse, Screen ; for MouseGetPos
SetWinDelay, -1 ; for WinActivate
;---------------------------------------------
IfNotEqual, wParam, 2, Return ; HTCAPTION (only part of title bar)
M_old_X := lParam & 0xFFFF, M_old_Y := lParam >> 16 & 0xFFFF
WinActivate, ahk_id %hWnd%
For each, Handle in MoveTogetherHandles
WinGetPos, W%A_Index%_old_X
, W%A_Index%_old_Y
, W%A_Index%_W
, W%A_Index%_H
, ahk_id %Handle%
While GetKeyState("LButton") {
MouseGetPos, M_new_X, M_new_Y
; get dX and dY from mouse, remember X and Y for next iteration
dX := M_new_X - M_old_X, M_old_X := M_new_X
, dY := M_new_Y - M_old_Y, M_old_Y := M_new_Y
; calc new X and Y for W[i], updating old X and Y
Loop, % MoveTogetherHandles.Length()
W%A_Index%_new_X := W%A_Index%_old_X += dX
, W%A_Index%_new_Y := W%A_Index%_old_Y += dY
; DeferWindowPos cycle
hDWP := DllCall("BeginDeferWindowPos", "Int", MoveTogetherHandles.Length(), "Ptr")
For each, Handle in MoveTogetherHandles
hDWP := DllCall("DeferWindowPos", "Ptr", hDWP
, "Ptr", Handle, "Ptr", 0
, "Int", W%A_Index%_new_X
, "Int", W%A_Index%_new_Y
, "Int", W%A_Index%_W
, "Int", W%A_Index%_H
, "UInt", 0x0214, "Ptr")
DllCall("EndDeferWindowPos", "Ptr", hDWP)
}
}