Moving a Gui Window before it's shown

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
PaulLeavitt
Posts: 58
Joined: 21 Oct 2014, 10:04

Moving a Gui Window before it's shown

30 Jan 2015, 13:14

Hello All! So I have a particularly vexing situation. I am running a dual monitor setup (different sized monitors too), and since I'm usually using my main application on my second (and larger) monitor, I would like my AHK Gui's to show up on that monitor. I finally developed a way to force popup's to appear centered on top of the last active window, but it requires that the popup (my Gui in this case) to be shown before it's moved, which looks bad.
So my question is this: with GUI's, is there a way to move them after they're created, but before they're shown?

Alternatively, is there a way I could use an expression in the Gui, Show line to determine it's location? use expressions for the X and Y coordinates, along with the width/height of the GUI to center it on a window?
Thanks!
Paul
MJs
Posts: 454
Joined: 23 Sep 2014, 03:29

Re: Moving a Gui Window before it's shown

30 Jan 2015, 13:46

is there a way to move them after they're created, but before they're shown?
it's simple, see if this helps:
use Gui, Show, Hide ; the window is hidden
then
Get the window itself position by means of WinGetPos; you way want to use DetectHiddenWindows
and move it as you want, with Gui, Show or WinMove
is there a way I could use an expression in the Gui, Show line to determine it's location
NO, but use the method above
use expressions for the X and Y coordinates, along with the width/height of the GUI to center it on a window?
same as above, except get the position of the window in question, and make your math to center your GUI it
if by expressions you mean expression
By contrast, the expression method omits the percent signs around variable names, but encloses literal strings in quotes. Thus, the following are the expression equivalents of the previous examples:
MsgBox % "The value in the variable named Var is " . Var . "." ; A period is used to concatenate (join) two strings.
CopyOfVar := Var
one more thing, your approach is a bit strange, and I'm not sure if it is 100% accurate, if so and if you can, post your sample code for that specific task
User avatar
T_Lube
Posts: 67
Joined: 22 Oct 2014, 00:57

Re: Moving a Gui Window before it's shown

31 Jan 2015, 15:59

"Gui, Show" has as part of it coordinates to show. You could have it show on the other monitor I am assuming. You might need to use some kind of DllCall to find out which monitor or something, not sure of the syntax on that myself, but I am sure you can find it on the forum. If that doesn't work, set in the gui options, +LastFound and then use the WinMove command as though the Gui was last found. 2 options for you.
lexikos
Posts: 9690
Joined: 30 Sep 2013, 04:07
Contact:

Re: Moving a Gui Window before it's shown

31 Jan 2015, 19:58

You can use the SysGet command to get the coordinates of a monitor.
User avatar
T_Lube
Posts: 67
Joined: 22 Oct 2014, 00:57

Re: Moving a Gui Window before it's shown

31 Jan 2015, 21:09

Oh yeah forgot about that one. :facepalm:
Guest

Re: Moving a Gui Window before it's shown

31 Jan 2015, 22:34

Code: Select all

WinGetPos,X,Y,Width,Height,A
Xpos:=X+Width/2-50
Ypos:=Y+Height/2-50
Gui, Add, Button,  x8 y8 w100 h100
Gui, Show, x%Xpos% y%Ypos%
User avatar
T_Lube
Posts: 67
Joined: 22 Oct 2014, 00:57

Re: Moving a Gui Window before it's shown

01 Feb 2015, 01:49

I am pretty sure that you only need to set the Gui position in "Gui, Show" parameters, pardon the mis-nomer.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: mstrauss2021, peter_ahk, Spawnova, zephyrus2706 and 351 guests