How to position the second gui in the center of previous gui?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
m3user
Posts: 235
Joined: 17 Jan 2014, 18:11

How to position the second gui in the center of previous gui?

15 Apr 2021, 04:25

Hi, is there an easy way to always display the second opened gui window in the center position of the previous gui window? Thanks.

Code: Select all

gui, 1:add, button, gOpen, Open another window
gui, 1:show, x200 y200 w400 h400
return

Open:
gui, 2:add, text,, How position this window`nto the center of previous window?
gui, 2:show, w200 h200
return
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: How to position the second gui in the center of previous gui?

15 Apr 2021, 05:03

Code: Select all

x1 := 100
y1 := 100
gui, 1:add, button, gOpen, Open another window
gui, 1:show,% "x" x1 " y" y1 " w400 h400"
return

Open:
	gui, 2:add, text,, How position this window`nto the center of previous window?
	gui, 2:show,% "x" x1+100 " y" y1+100 " w200 h200"
	return
Well, there might be a dedicated command available that I might have missed ... so it's just math for now. Tested.
m3user
Posts: 235
Joined: 17 Jan 2014, 18:11

Re: How to position the second gui in the center of previous gui?

15 Apr 2021, 06:08

Thanks, I was hoping for a more general solution. In this one I would, for each case, have to calculate the position based on sizes of both windows to get it centered.
Any other idea?
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: How to position the second gui in the center of previous gui?

15 Apr 2021, 06:12

Well, the Gui is a standard window, so you can use AHK‘s Window-command set within a function to detect a windows/guis current details and do whatever math on them there, like: % "x" . gui1X+((gui1Width-gui2Width)/2) . " y" . gui1Y+((gui1Height-gui2Height)/2) (untested concept).
m3user
Posts: 235
Joined: 17 Jan 2014, 18:11

Re: How to position the second gui in the center of previous gui?

15 Apr 2021, 11:53

Thanks, I can do it this way.

I just wondered if there is a system way. It would be the same as using +Parent, but the window could be moved out from the first gui.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput, Google [Bot], mcd, Nerafius, RandomBoy, Rohwedder and 104 guests