I place my GUI somewhere on my two monitors; the used InputBox got no coordinates and is always in the centre of the first monitor.
Is there a simple way to place it always in the centre of the main-GUI?
Thanks in advance.
Inputbox in the centre of the GUI
Inputbox in the centre of the GUI
Peter (AHK Beginner) / Win 10 x64, AHK Version v1.1.33
Re: Inputbox in the centre of the GUI
have no idea with 2 monitors , example inputbox in centre of GUI
Code: Select all
;- inputboxx middle of the GUI
gh:=300
gw:=700
gx:=200
gy:=100
Gui,show,x%gx% y%gy% h%gh% w%gw%,Test
gosub,a1
return
Guiclose:
exitapp
a1:
w:=300
h:=100
InputBox, OutputVar, Test, , , %w%, %h%, % (gx+(gw/2-(w/2))), % (gy+(gh/2-(h/2))),, 2147483,1234
if ErrorLevel
return
MsgBox, You entered= %OutputVar%
return
Re: Inputbox in the centre of the GUI
Hi Garry
this code shows it in the middle of the the newly created, unmoved GUI. If I move the GUI and starts the InputBox again, then it is not in the middle of the current GUI - it is where it was before:
this code shows it in the middle of the the newly created, unmoved GUI. If I move the GUI and starts the InputBox again, then it is not in the middle of the current GUI - it is where it was before:
Code: Select all
;- inputboxx middle of the GUI
gh:=300
gw:=700
gx:=200
gy:=100
Gui, Add, Button, ga1, Show Inputbox...
Gui,show,x200 y100 h%gh% w%gw%,Test
gosub,a1
return
Guiclose:
exitapp
a1:
w:=300
h:=100
InputBox, OutputVar, Test, , , %w%, %h%, % (gx+(gw/2-(w/2))), % (gy+(gh/2-(h/2))),, 2147483,1234
if ErrorLevel
return
MsgBox, You entered= %OutputVar%
return
Peter (AHK Beginner) / Win 10 x64, AHK Version v1.1.33
Re: Inputbox in the centre of the GUI
Get the ID of the GUI by using the +Hwnd option of the Gui command, then use WinGetPos to get the current position of the GUI window with that ID right before you create the InputBox.
Re: Inputbox in the centre of the GUI
Thanks boiler
I will try.
I will try.
Peter (AHK Beginner) / Win 10 x64, AHK Version v1.1.33
Re: Inputbox in the centre of the GUI
this opens Inputbox in the middle of GUI ( also when GUI moved )
( I use Edit instead of inputbox )
( I use Edit instead of inputbox )
Code: Select all
;- inputboxx middle of the GUI
gh:=300
gw:=700
Gui,add,button , x10 y270 h25 w150 gA1,OPEN_INPUTBOX
Gui,show,x100 y20 h%gh% w%gw%,Test
gosub,a1
return
Guiclose:
exitapp
a1:
w:=300
h:=100
Gui, +LastFound
Gui_ID := WinExist()
WinGetPos,x,y,w1,h1,ahk_id %GUI_ID%
InputBox, OutputVar, Test, , , %w%, %h%, % (x+(gw/2-(w/2))), % (y+(gh/2-(h/2))),, 2147483,1234
if ErrorLevel
return
MsgBox, You entered= %OutputVar%
return
Re: Inputbox in the centre of the GUI
Thanks Garry
here is my code fragment which does the same. The main difference is that I use "A" for active window, you use LastFound and WinExist
I tried to calculate it with a subroutine, but failed:
I'm sure there are some stupid errors in it.
here is my code fragment which does the same. The main difference is that I use "A" for active window, you use LastFound and WinExist
Code: Select all
...
WinGetPos , Xpos, Ypos, Width, Height, A ; Data from "a"ctive window
aktb := 330 ; set width for Inputbox
akth := 150 ; set height for Inputbox
InputBox, myvar, MyApp, Please write something,,%aktb%,%akth%,(Xpos + (width * 0.5) - (aktb * 0.5)),Ypos + (height * 0.5) - (akth * 0.5)
Code: Select all
aktb := 330 ; set width for Inputbox
akth := 150 ; set height for Inputbox
InputBox, myvar, MyApp, Please write something,,%aktb%,%akth%,myPos("x",%aktb%),myPos("y",%akth%)
....
mypos(modus,value)
{
WinGetPos , Xpos, Ypos, Width, Height, A ; A für aktives Window
Ifequal, modus, X
{
value := (Xpos + (width * 0.5) - (value * 0.5))
}
Ifequal, modus, Y
{
value := Ypos + (height * 0.5) - (value * 0.5)
}
}
return
Peter (AHK Beginner) / Win 10 x64, AHK Version v1.1.33
Re: Inputbox in the centre of the GUI
garys script works fine on my end. Does it not work for you?
Instead of using WinExist(), LastFound or "A" explicitly define an hwnd to your gui.
Instead of using WinExist(), LastFound or "A" explicitly define an hwnd to your gui.
Code: Select all
ibW := 400, ibH := 200
Gui New, +HwndhGui
Gui %hGui%:Add, Button, ga1, Show Inputbox...
Gui %hGui%:show,x200 y100 h300 w700,Test
gosub,a1
return
Guiclose:
exitapp
a1:
WinGetPos, gx, gy, gw, gh, ahk_id %hGui%
ibX := Round( gx + ( gw / 2 ) - ( ibW / 2 ) )
, ibY := Round( gy + ( gh / 2 ) - ( ibH / 2 ) )
InputBox, OutputVar, Title, Prompt,, %ibW%, %ibH%, %ibX%, %ibY%,,, Default
if ErrorLevel
return
MsgBox, You entered= %OutputVar%
return
Re: Inputbox in the centre of the GUI
Hi dd900
yes, it works for me now.
I tried the +Hwnd before, but made some mistake. I will try again.
If I use 10 Inputboxes with different sizes, I need ten times the code. It would be great to store the WinGetPos and the current calculation in a subroutine / function ....
yes, it works for me now.
I tried the +Hwnd before, but made some mistake. I will try again.
If I use 10 Inputboxes with different sizes, I need ten times the code. It would be great to store the WinGetPos and the current calculation in a subroutine / function ....
Peter (AHK Beginner) / Win 10 x64, AHK Version v1.1.33
Re: Inputbox in the centre of the GUI
You could always use an Array to store the InputBox sizes.
Why do you need so many different sizes?
Why do you need so many different sizes?
Last edited by dd900 on 02 Aug 2015, 13:55, edited 1 time in total.
Re: Inputbox in the centre of the GUI
Yes, but how this will help to avoid a "WinPetPos + Calculation" section before every InputBox?dd900 wrote:You could always use an Array to ...
At the moment I need 2 or three different ones, because there is input of short and long strings, and I want to display the value without scrolling (if possible...)dd900 wrote:...Why do you need so many different sizes?
Peter (AHK Beginner) / Win 10 x64, AHK Version v1.1.33
Re: Inputbox in the centre of the GUI
You will either have to do the calculation everytime you move/resize the gui or whenever you call an InputBox. Otherwise you will not have updated coords and size when the gui has changed positions.
This can be shortened even further depending on how you code everything.
Code: Select all
ibSize := [ { w: 300, h: 200 }, { w: 350, h: 250 } ]
Gui New, +HwndhGui
Gui %hGui%:Add, Button, ga1, Inputbox1
Gui %hGui%:Add, Button, ga2, Inputbox2
Gui %hGui%:show,x200 y100 h300 w700,Test
gosub,a1
return
Guiclose:
exitapp
getWinPos:
WinGetPos, gx, gy, gw, gh, ahk_id %hGui%
ibX := Round( gx + ( gw / 2 ) - ( ibSize[ ib ].w / 2 ) )
, ibY := Round( gy + ( gh / 2 ) - ( ibSize[ ib ].h / 2 ) )
return
a1:
ib := 1
gosub getWinPos
InputBox, OutputVar, Title, Prompt,, % ibSize[ ib ].w, % ibSize[ ib ].h, %ibX%, %ibY%,,, Default
gosub ibReturn
return
a2:
ib := 2
gosub getWinPos
InputBox, OutputVar, Title, Prompt,, % ibSize[ ib ].w, % ibSize[ ib ].h, %ibX%, %ibY%,,, Default
gosub ibReturn
return
ibReturn:
if ErrorLevel
MsgBox, Error
else
MsgBox, You entered= %OutputVar%
return
Re: Inputbox in the centre of the GUI
Yes, that's clear.dd900 wrote:You will either have to do the calculation everytime you move/resize the gui or ...
I have a rather long, slow, low level style to code. "Shortening" is not my specialitydd900 wrote:...This can be shortened even further depending on how you code everything.
Yepp, I think that's the trick. Flexible and short.dd900 wrote:Code: Select all
.... a1: ib := 1 gosub getWinPos ....
Thanks
Peter (AHK Beginner) / Win 10 x64, AHK Version v1.1.33
Re: Inputbox in the centre of the GUI
I hope you get everything worked out. Good luck with your script.
Code: Select all
ibSize := { ib1: { w: 400, h: 200 }, ib2: { w: 450, h: 250 } }
Gui New, +HwndhGui
Gui %hGui%:Add, Button, vib1 gibShow, Inputbox1
Gui %hGui%:Add, Button, vib2 gibShow, Inputbox2
Gui %hGui%:show,x200 y100 h300 w700,Test
OnMessage( 0x0047, "WM_WINDOWPOSCHANGED" )
WM_WINDOWPOSCHANGED()
return
GuiClose( hwnd ) {
exitapp
}
WM_WINDOWPOSCHANGED() {
global
WinGetPos, gx, gy, gw, gh, ahk_id %hGui%
return
}
ibShow() {
global
InputBox, OutputVar, Title, Prompt, 0
, % ibSize[ A_GuiControl ].w
, % ibSize[ A_GuiControl ].h
, % Round( gx + ( gw / 2 ) - ( ibSize[ A_GuiControl ].w / 2 ) )
, % Round( gy + ( gh / 2 ) - ( ibSize[ A_GuiControl ].h / 2 ) ),,, Default
if ErrorLevel
MsgBox, Error
else
MsgBox, You entered= %OutputVar%
return
}
Re: Inputbox in the centre of the GUI
EDIT: sorry - mixed up the forum language. See English below.
------------------------------
Nur zur Vollständigkeit (ich bin mit der aktuellen Lösung zufrieden):
Das Programm ist mathematisch und codetechnisch in Ordnung, aber die Inputbox sitzt zwar ziemlich, aber nicht genau in der Mitte. (Da müssten sich die Mittelpunkte überlagern und die Seitenabstände gleich sein).
Ich habe auf meinem Display "Win 7 x64, 120 dpi, Zoom 125%" - wirkt sich das aus?
-------------------------
Just for completeness (I am satisfied with the current solution):
The program is mathematically and per code ok, but the Inputbox is placed ratherbut not exactly in the middle. (Since the midpoints would overlap and side clearances should be the same).
I have on my screen "Win 7 x64, 120 dpi, 125% Zoom" - does this affect me?
------------------------------
Nur zur Vollständigkeit (ich bin mit der aktuellen Lösung zufrieden):
Das Programm ist mathematisch und codetechnisch in Ordnung, aber die Inputbox sitzt zwar ziemlich, aber nicht genau in der Mitte. (Da müssten sich die Mittelpunkte überlagern und die Seitenabstände gleich sein).
Ich habe auf meinem Display "Win 7 x64, 120 dpi, Zoom 125%" - wirkt sich das aus?
-------------------------
Just for completeness (I am satisfied with the current solution):
The program is mathematically and per code ok, but the Inputbox is placed ratherbut not exactly in the middle. (Since the midpoints would overlap and side clearances should be the same).
I have on my screen "Win 7 x64, 120 dpi, 125% Zoom" - does this affect me?
Last edited by Peter2 on 03 Aug 2015, 14:18, edited 1 time in total.
Peter (AHK Beginner) / Win 10 x64, AHK Version v1.1.33
Re: Inputbox in the centre of the GUI
Gui New, +HwndhGui -DPIScale
Re: Inputbox in the centre of the GUI
... or:
BTW: Using this code, the whole area of the InputBox will be roughly centered whithin the whole area of the Gui window. If you want to center the client area within the client area of the Gui, you'll need other code.
Code: Select all
#NoEnv
IBSize := [{W: 300, H: 200}, {W: 350, H: 250}]
ScaleDown := 96 / A_ScreenDPI
Gui, New, +HwndhGui
Gui, %hGui%:Add, Button, gIB1, Inputbox1
Gui, %hGui%:Add, Button, gIB2, Inputbox2
Gui, %hGui%:show, x200 y100 h300 w700, Test
Gosub, IB1
Return
Guiclose:
ExitApp
GetWinPos:
WinGetPos, GX, GY, GW, GH, ahk_id %hGui%
IBX := Round((GX + (GW / 2) - (IBSize[IB].W / 2)) * ScaleDown)
IBY := Round((GY + (GH / 2) - (IBSize[IB].H / 2)) * ScaleDown)
Return
IB1:
IB2:
IB := SubStr(A_ThisLabel, 3)
Gosub, GetWinPos
InputBox, OutputVar, Title, Prompt, , % IBSize[IB].w, % IBSize[IB].h, %IBX%, %IBY%, , , Default
If ErrorLevel
MsgBox, Error
Else
MsgBox, You entered: %OutputVar%
Return
Re: Inputbox in the centre of the GUI
BTW: Wouldn't that be an interessting feature request for InputBox in a future version of AHK?
The current behaviour - if GUI is on second monitor (or at the border of wide-screen) and the IB appears always in the middle of first monitor - could be improved via an additional option.
The current behaviour - if GUI is on second monitor (or at the border of wide-screen) and the IB appears always in the middle of first monitor - could be improved via an additional option.
Peter (AHK Beginner) / Win 10 x64, AHK Version v1.1.33
Who is online
Users browsing this forum: Google [Bot], Insanibaccha, PsysimSV and 205 guests