;-------------------------------------------------------------------------------MoveTogether(wParam, lParam ="", _ ="", hWnd =""){; using DeferWindowPos;-------------------------------------------------------------------------------; call MoveTogether(Handles) with an array of handles; to set up a bundle of AHK Gui's that move together;---------------------------------------------------------------------------; https://autohotkey.com/boards/viewtopic.php?p=199402#p199402; version 2018.02.08

;-------------------------------------------------------------------------------MoveTogether(wParam, lParam ="", _ ="", hWnd =""){; using DeferWindowPos;-------------------------------------------------------------------------------; call MoveTogether(Handles) with an array of handles; to set up a bundle of AHK Gui's that move together;---------------------------------------------------------------------------; https://autohotkey.com/boards/viewtopic.php?p=199402#p199402; version 2018.02.08

[size=150]Thanks to all contributors for your collaboration. Team work for the win :thumbup: :D :bravo: [/size]

I have taken the time to read all the suggestion for improvement again. So here is, hopefully, a generally useful function:[list][*]an array of handles can be passed to the function to set up, thx [b]Helgef[/b][*]no more worries about settings leaking, thx [b]guest3456[/b] for raising the issue, thx [b]Helgef[/b] for solving it[*]implemented Shifting, thx [b]digidings[/b] for suggeting and [b]iPhilip[/b] for improving[*]rewrite using Win{}, thx [b]iPhilip[/b][/list][code]

;-------------------------------------------------------------------------------MoveTogether(wParam, lParam = "", _ = "", hWnd = "") { ; using DeferWindowPos;------------------------------------------------------------------------------- ; call MoveTogether(Handles) with an array of handles ; to set up a bundle of AHK Gui's that move together ;--------------------------------------------------------------------------- ; https://autohotkey.com/boards/viewtopic.php?p=199402#p199402 ; version 2018.02.08

;-------------------------------------------------------------------------------MoveTogether(wParam, lParam ="", _ ="", hWnd =""){; using DeferWindowPos;-------------------------------------------------------------------------------; call MoveTogether(Handles) with an array of handles; to set up a bundle of AHK Gui's that move together;---------------------------------------------------------------------------; https://autohotkey.com/boards/viewtopic.php?p=199402#p199402; version 2018.02.08

Guiclose:;- when close Listbox-GUI close also attached DOSWinClose, ahk_pid %pid2%;- if close only DOS , ahk-script freeze but you can close itWinWaitClose,ahk_pid %pid2%exitapp;------------------------------------

;-------------------------------------------------------------------------------MoveTogether(wParam, lParam ="", _ ="", hWnd =""){; using DeferWindowPos;-------------------------------------------------------------------------------; call MoveTogether(Handles) with an array of handles; to set up a bundle of AHK Gui's that move together;---------------------------------------------------------------------------; https://autohotkey.com/boards/viewtopic.php?p=199402#p199402; version 2018.02.08

Guiclose: ;- when close Listbox-GUI close also attached DOSWinClose, ahk_pid %pid2% ;- if close only DOS , ahk-script freeze but you can close itWinWaitClose,ahk_pid %pid2%exitapp;------------------------------------

@ iPhilip: Thank you very much. I noticed how nicely you dealt with the associative array and the ingenious idea to put all computations where they are needed. Removing one of three loops.

@ [b]iPhilip[/b]: Thank you very much. :thumbup: I noticed how nicely you dealt with the associative array and the ingenious idea to put all computations where they are needed. Removing one of three loops. :dance:

Thank you for your work. While it is true that the function moves AutoHotkey Guis together, if the window being dragged is a AutoHotkey Gui, it will also move any other window whose handle has been added to the Handles array. The script below demonstrates that with an additional Notepad window. I took the liberty of simplifying the function a bit by using an associative array and added the ability of pressing the Shift key to disable moving the other windows. Here is the script:

Thank you for your work. While it is true that the function moves AutoHotkey Guis together, if the window being dragged is a AutoHotkey Gui, it will also move any other window whose handle has been added to the [c]Handles[/c] array. The script below demonstrates that with an additional Notepad window. I took the liberty of simplifying the function a bit by using an associative array and added the ability of pressing the Shift key to disable moving the other windows. Here is the script:[code=autohotkey file=MoveTogether v2.ahk]#NoEnv#SingleInstance Force

@Nextron: Nice hint, thank you very much. I want my spinner to attach to the Edit1 control of notepad.exe as one of the demos.I will have to do more homework to figure out the details for that.

I use currently SetParent to take care of the movement with some styles applied to my Gui to allow click through. That seems to work perfectly on Win10 but not on Win7.

@[color=#FF00FF] [b]Nextron[/b][/color]: Nice hint, thank you very much. I want my spinner to attach to the Edit1 control of notepad.exe as one of the demos.I will have to do more homework to figure out the details for that.

I use currently [c]SetParent[/c] to take care of the movement with some styles applied to my Gui to allow click through. That seems to work perfectly on Win10 but not on Win7.

Nice, I used an application which has an option similar to this, but doesn't fully suit my needs. Using AHK with WinMove to mimic it just didn't look smooth enough, but this looks good and probably is the same method used by that other app.

I think with WinEventProc using EVENT_SYSTEM_MOVESIZESTART and EVENT_SYSTEM_MOVESIZEEND as a trigger, you can make it work for non-AHK windows too.

Nice, I used an application which has an option similar to this, but doesn't fully suit my needs. Using AHK with [c]WinMove[/c] to mimic it just didn't look smooth enough, but this looks good and probably is the same method used by that other app.

I think with WinEventProc using EVENT_SYSTEM_MOVESIZESTART and EVENT_SYSTEM_MOVESIZEEND as a trigger, you can make it work for non-AHK windows too.

I wrote first a similar function for a related project (class Spinner), where Spinner.Handles is accessible in the function since Spinner is a superglobal. (not sure if that's the right expression)In my use-case, I don't use the global, I put it in the general function as a hint how to use the function. Obviously a better approach to make it more general is how Helgef is showing, Thanks for that, btw.I had a look at DockA as well and I don't understand most of it, but it looks very professional. I'm sure DockA will sort things out correctly, where my simple spinner won't need to get anything done at all.

DockA comments wrote:windows will behave like single window - moving, sizing, focusing, hiding and other OS events will be handled by the module so that the "composite window" behaves like the single window.

The intended purpose of my function is to allow for several spinners to be shown and move them around fast when I move the top-level GUI.Thank you very much for the tips how to store and restore settings. I will keep this good advice in mind.

@[b]guest3456[/b] and [b]Helgef[/b] Thank you for your feedback!

I wrote first a similar function for a related project (class Spinner), where [c]Spinner.Handles[/c] is accessible in the function since Spinner is a superglobal. (not sure if that's the right expression)In my use-case, I don't use the global, I put it in the general function as a hint how to use the function. Obviously a better approach to make it more general is how [b]Helgef[/b] is showing, Thanks for that, btw.I had a look at DockA as well and I don't understand most of it, but it looks very professional. I'm sure DockA will sort things out correctly, where my simple spinner won't need to get anything done at all.[quote="DockA comments"]windows will behave like single window - moving, sizing, focusing, hiding and other OS events will be handled by the module so that the "composite window" behaves like the single window.[/quote]The intended purpose of my function is to allow for several spinners to be shown and move them around fast when I move the top-level GUI.Thank you very much for the tips how to store and restore settings. I will keep this good advice in mind.

As guest3456 indicated, you do not need global variables or settings. The Handles can be passed as the first parameter and stored in a static variable, and the settings can be set inside the function. Since OnMessage callbacks always run in new threads, there is no need to restore settings before the function returns. Example,

As [b]guest3456[/b] indicated, you do not need global variables or settings. The [c]Handles[/c] can be passed as the first parameter and stored in a static variable, and the settings can be set inside the function. Since [c]OnMessage[/c] callbacks always run in new [docs]threads[/docs], there is no need to restore settings before the function returns. Example,[code]#NoEnv#SingleInstance Force; #Include, MoveTogether.ahk

i've used majkinetor's DockA script in the past for this use-case. not sure whether i like your solution better or not. I don't really like your global Handles var. DockA lets me pass individual hwnds in. anyway, its good work. two things:

1. i dont think you should be globally setting SetBatchLines, CoordMode, etc. i think you should save the old values, then change them in the func, and then change them back:

maybe it doesn't matter much for WinDelay and BatchLines, but it is pretty important not to change CoordMode

2. i dont think you should claim it moves "windows" together, but rather "ahk guis". the NCLBUTTONDOWN msg will only fire on your AHK guis, not other windows

i've used majkinetor's [url=https://github.com/majkinetor/mm-autohotkey/blob/master/DockA/DockA.ahk]DockA[/url] script in the past for this use-case. not sure whether i like your solution better or not. I don't really like your global Handles var. DockA lets me pass individual hwnds in. anyway, its good work. two things:

1. i dont think you should be globally setting SetBatchLines, CoordMode, etc. i think you should save the old values, then change them in the func, and then change them back:

I don't know what's causing this problem... Seems to be a nice idea though.

Edit: I found the problem: I was running the code in CodeQuickTester, that runs the script though a "pipe". Not sure why that made a difference. Sorry for the disturbance.

I know. You have to download the gif. Dropbox doesn't play it.

Here's a link to webm, if that's easier. https://preview.tinyurl.com/derz00Dropbox

I don't know what's causing this problem... Seems to be a nice idea though.

[b]Edit[/b]: I found the problem: I was running the code in [url=https://autohotkey.com/boards/viewtopic.php?f=6&t=6113]CodeQuickTester[/url], that runs the script though a "pipe". Not sure why that made a difference. Sorry for the disturbance. :cry:

... just a small modification in the function MoveTogether so that when Shift is held down it's possible to move a single window out of the group e.g. for rearranging ...[code]While GetKeyState("LButton") and !GetKeyState("Shift") {[/code]

Grab one of the windowsAHK Guis by the titlebar and move it around. The others will move together with it.

Just push all handles of interest into a global array called Handles, and include the function.The example includes inside the autoexecute section, which will run three lines of "modifying".The function could read the current settings, modify as needed and restore afterwards.

EDIT: clarified the fact that function only works for AHK Gui'sEDIT2: keep reading, what follows is a collaboration to improve the function, or see the improved function here.Edit3: added a link to Lexikos' teaching session

Here is a function that moves [strike]windows[/strike] [u]AHK Guis[/u] together:[spoiler][code]

GuiClose:ExitApp[/code]Grab one of the [strike]windows[/strike] [u]AHK Guis[/u] by the titlebar and move it around. The others will move together with it.

[hr][/hr]Just push all handles of interest into a global array called [c]Handles[/c], and include the function.The example includes inside the autoexecute section, which will run three lines of "modifying".The function could read the current settings, modify as needed and restore afterwards.

[hr][/hr]Thx to [b][color=#FF0000]Lexikos[/color][/b] for teaching how to use [i]DeferWindowPos[/i].https://autohotkey.com/boards/viewtopic.php?f=5&t=15052&hilit=DeferWindowPos

[hr][/hr]EDIT: clarified the fact that function only works for AHK Gui's[color=#0000FF]EDIT2: keep reading, what follows is a collaboration to improve the function, [/color][size=125] [url=https://autohotkey.com/boards/viewtopic.php?p=199402#p199402]or see the improved function here[/url].[/size]Edit3: added a link to Lexikos' teaching session