MoveTogether()

Post a reply

Confirmation code
Enter the code exactly as it appears. All letters are case insensitive.
Smilies
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :| :mrgreen: :geek: :ugeek: :arrow: :angel: :clap: :crazy: :eh: :lolno: :problem: :shh: :shifty: :sick: :silent: :think: :thumbup: :thumbdown: :salute: :wave: :wtf: :yawn: :facepalm: :bravo: :dance: :beard: :morebeard: :xmas: :HeHe: :trollface: :cookie: :rainbow: :monkeysee: :monkeysay: :happybday: :headwall: :offtopic: :superhappy: :terms: :beer:
View more smilies

BBCode is ON
[img] is OFF
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: MoveTogether()

Re: MoveTogether()

Post by elmo » 12 Sep 2018, 08:31

@wolf_II

This is soooo good. Thank you for sharing.

Re: MoveTogether()

Post by wolf_II » 18 Feb 2018, 14:30

Try this:

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

I hope that helps.

Re: MoveTogether()

Post by JasonDavisFL » 17 Feb 2018, 20:57

This is awesome! Anyway to minimize all at once and then restore?

Re: MoveTogether()

Post by wolf_II » 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]GeSHi © Codebox Plus


Example:

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


I also added a link in the first post.



Edit: added comments: version and link to here

Re: MoveTogether()

Post by garry » 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]GeSHi © Codebox Plus



2nd Example : Listbox , send selected commands to DOS

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

Re: MoveTogether()

Post by wolf_II » 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:

Re: MoveTogether()

Post by iPhilip » 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]GeSHi © Codebox Plus

Cheers!

Re: MoveTogether()

Post by guest3456 » 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.

Re: MoveTogether()

Post by wolf_II » 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.

Re: MoveTogether()

Post by Nextron » 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.

Re: MoveTogether()

Post by wolf_II » 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:

Re: MoveTogether()

Post by wolf_II » 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.

Re: MoveTogether()

Post by Helgef » 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]GeSHi © Codebox Plus


Cheers.

Re: MoveTogether()

Post by guest3456 » 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]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

Re: MoveTogether()

Post by derz00 » 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:

Re: MoveTogether()

Post by wolf_II » 22 Jan 2018, 17:56

@derz00: I don't understand, I can see a single image, no video.

Re: MoveTogether()

Post by wolf_II » 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

Re: MoveTogether()

Post by derz00 » 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

Re: MoveTogether()

Post by digidings » 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 ...

Code: [Select all]GeSHi © Codebox Plus

While GetKeyState("LButton") and !GetKeyState("Shift") {


cheers :thumbup:

MoveTogether()

Post by wolf_II » 22 Jan 2018, 16:11

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


Example:

Code: [Select all] [Expand]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

Top