MoveTogether()

Post your working scripts, libraries and tools
wolf_II
Posts: 2100
Joined: 08 Feb 2015, 20:55

MoveTogether()

22 Jan 2018, 16:11

Here is a function that moves windows AHK Guis together:
Spoiler


Example:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus


Grab one of the windows AHK 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.



Thx to Lexikos for teaching how to use DeferWindowPos.
https://autohotkey.com/boards/viewtopic ... rWindowPos



EDIT: clarified the fact that function only works for AHK Gui's
EDIT2: 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
Last edited by wolf_II on 12 Feb 2018, 09:31, edited 3 times in total.
digidings
Posts: 3
Joined: 22 Jan 2018, 17:04

Re: MoveTogether()

22 Jan 2018, 17:10

Nice code! :bravo:

... 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 ...


cheers :thumbup:
User avatar
derz00
Posts: 495
Joined: 02 Feb 2016, 17:54
GitHub: derz00
Location: Middle of the round cube

Re: MoveTogether()

22 Jan 2018, 17:24

Hey, this looked interesting, but didn't work very well.

https://tinyurl.com/y7vgkxk9 Dropbox doesn't play gifs but you can download
try it and see
...
wolf_II
Posts: 2100
Joined: 08 Feb 2015, 20:55

Re: MoveTogether()

22 Jan 2018, 17:54

digidings wrote:While GetKeyState("LButton") and !GetKeyState("Shift")

Excellent idea! Thanks for sharing, I'm glad you like it. :D
wolf_II
Posts: 2100
Joined: 08 Feb 2015, 20:55

Re: MoveTogether()

22 Jan 2018, 17:56

@derz00: I don't understand, I can see a single image, no video.
User avatar
derz00
Posts: 495
Joined: 02 Feb 2016, 17:54
GitHub: derz00
Location: Middle of the round cube

Re: MoveTogether()

22 Jan 2018, 18:05

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.

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. :cry:

:wave:
try it and see
...
guest3456
Posts: 2392
Joined: 09 Oct 2013, 10:31

Re: MoveTogether()

23 Jan 2018, 11:08

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:

Code: [Select all] [Download] GeSHi © Codebox Plus

oldwindelay := A_WinDelay
SetWinDelay, -1
;... your code
SetWinDelay, %oldwindelay%


that way your function has no side effects

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

Helgef
Posts: 3151
Joined: 17 Jul 2016, 01:02
Contact:

Re: MoveTogether()

23 Jan 2018, 11:45

Nice one thanks for sharing :thumbup:

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,

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus


Cheers.
wolf_II
Posts: 2100
Joined: 08 Feb 2015, 20:55

Re: MoveTogether()

23 Jan 2018, 12:59

@guest3456 and Helgef Thank you for your feedback!

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.
wolf_II
Posts: 2100
Joined: 08 Feb 2015, 20:55

Re: MoveTogether()

23 Jan 2018, 13:12

I only just realized the truth of what guest3456 writes about non-AHK windows: they don't care about or respond to my onMeesage. I will edit the OP.
Thx again for the insight. :thumbup:
User avatar
Nextron
Posts: 1207
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win7 x64 AHK: Unicode x32

Re: MoveTogether()

23 Jan 2018, 16:02

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.
wolf_II
Posts: 2100
Joined: 08 Feb 2015, 20:55

Re: MoveTogether()

23 Jan 2018, 16:28

@ 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.
guest3456
Posts: 2392
Joined: 09 Oct 2013, 10:31

Re: MoveTogether()

24 Jan 2018, 11:45

Nextron wrote: 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


wolf_2 is using DeferWindowPos, which doesn't suffer from the lagging of doing WinMove within a loop.

iPhilip
Posts: 288
Joined: 02 Oct 2013, 12:21

Re: MoveTogether()

26 Jan 2018, 13:38

Hi Wolf_II,

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:

Code: [Select all] [Expand] [Download] (MoveTogether v2.ahk)GeSHi © Codebox Plus

Cheers!
Windows 7 Pro (64 bit) - AutoHotkey v1.1+ (Unicode 32-bit)
wolf_II
Posts: 2100
Joined: 08 Feb 2015, 20:55

Re: MoveTogether()

26 Jan 2018, 14:18

@ iPhilip: 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:
garry
Posts: 1415
Joined: 22 Dec 2013, 12:50

Re: MoveTogether()

08 Feb 2018, 04:42

@wolf_II , thank you for the script
just tried to add x y w h variable to the last example from iPhilip
( define the first and followed positions )
EDIT1 : attached 3 ahk GUI examples and 2 programs
EDIT2 : used last changed function
EDIT3: added a 2nd example : Listbox , send selected commands to DOS

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



2nd Example : Listbox , send selected commands to DOS

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Last edited by garry on 12 Feb 2018, 13:19, edited 5 times in total.
wolf_II
Posts: 2100
Joined: 08 Feb 2015, 20:55

Re: MoveTogether()

08 Feb 2018, 16:07

Thanks to all contributors for your collaboration. Team work for the win :thumbup: :D :bravo:

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

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus


Example:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus


I also added a link in the first post.



Edit: added comments: version and link to here
JasonDavisFL
Posts: 9
Joined: 12 Jan 2018, 13:05
Facebook: JasonDavis83
GitHub: JasonDavisFL

Re: MoveTogether()

17 Feb 2018, 20:57

This is awesome! Anyway to minimize all at once and then restore?
wolf_II
Posts: 2100
Joined: 08 Feb 2015, 20:55

Re: MoveTogether()

18 Feb 2018, 14:30

Try this:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

I hope that helps.
elmo
Posts: 64
Joined: 09 Oct 2013, 09:08

Re: MoveTogether()

12 Sep 2018, 08:31

@wolf_II

This is soooo good. Thank you for sharing.

Return to “Scripts and Functions”

Who is online

Users browsing this forum: arcticir, w0z and 20 guests