Perpetually growing Window

Get help with using AutoHotkey and its commands and hotkeys
User avatar
BGM
Posts: 496
Joined: 20 Nov 2013, 20:56
GitHub: bgmCoder
Contact:

Perpetually growing Window

06 Dec 2013, 11:48

Salvete!

Hi, y'all. I have this problem where my GUI keeps growing. I made a post in StackOverflow with some code and explanation, but noone knows.
http://stackoverflow.com/questions/2038 ... dimensions

I am wondering if anyone has an idea of where to look.
User avatar
Chef
Posts: 50
Joined: 14 Nov 2013, 13:01

Re: Perpetually growing Window

06 Dec 2013, 13:02

What do you want to do with the dimensions? Save and restore?
User avatar
BGM
Posts: 496
Joined: 20 Nov 2013, 20:56
GitHub: bgmCoder
Contact:

Re: Perpetually growing Window

06 Dec 2013, 13:08

When the application shuts down, I save the values to an ini file. When I start the application, I read the values from the ini file.

The application loads the values correctly when it starts. The sizes never change in the ini file until I call the save position function just before exiting the GUI. I can't find any other reference to the window size variables anywhere! I'm really at a loss, and was hoping someone might have some abstract ideas of where to look.

The window width grows by 8 pixels every time I call wingetpos.
User avatar
Chef
Posts: 50
Joined: 14 Nov 2013, 13:01

Re: Perpetually growing Window

06 Dec 2013, 13:11

Last edited by Chef on 06 Dec 2013, 13:38, edited 1 time in total.
User avatar
LinearSpoon
Posts: 156
Joined: 29 Sep 2013, 22:55

Re: Perpetually growing Window

06 Dec 2013, 13:26

I had an issue like this before. WinGetPos includes the window title bar and borders, while Gui, show expects "client" coordinates (coordinates that don't include window borders). The result is that each time you use Gui, show and then get the window size with WinGetPos, it will grow.

You can try this for getting the width and height of the client area. WinGetPos is fine for x and y positions.

Code: Select all

VarSetCapacity(rect,16)
DllCall("GetClientRect", "ptr", hwnd, "ptr", &rect)  ;hwnd is the window handle of the gui (hint: Gui, +hwndmyvar)
width := NumGet(rect,8,"int"), height := NumGet(rect,12,"int")  
User avatar
BGM
Posts: 496
Joined: 20 Nov 2013, 20:56
GitHub: bgmCoder
Contact:

Re: Perpetually growing Window

06 Dec 2013, 14:01

Thanks! That was exactly the problem and the solution!

Now I remember having this problem using BCX code, too - I forgot all about that.

Are any of y'all using Stack Exchange? Maybe you could propose that as the answer?
http://stackoverflow.com/questions/2038 ... dimensions
lexikos
Posts: 7088
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Perpetually growing Window

09 Dec 2013, 02:32

There are (arguably) easier ways.
  • Use A_GuiWidth/Height as below to get the size, and Gui command to set it.
  • Use WinGetPos and its complement, WinMove.

Code: Select all

GuiSize:  ; Called when Gui is (re)sized.
WidthToSave := A_GuiWidth
HeightToSave := A_GuiHeight
return
User avatar
VxE
Posts: 44
Joined: 30 Sep 2013, 10:35
Location: Simi Valley, CA

Re: Perpetually growing Window

09 Dec 2013, 05:30

Remembering the gui position and restoring it is one of the items in my bag of tricks. Here's my take on it :

Code: Select all

; You can put an actual gui prior to this point.
	scriptCfg = %A_ScriptDir%\config.ini
	IniRead, guiPos, %scriptCfg%, Script, GuiPos ; Load gui pos
	If !InStr( guiPos, "," ) ; this checks for a missing file, key, or blank value
		guiPos = center,center,605,374,0 ; I put the default gui size and pos here
	StringSplit, g, guiPos, `,
	Gui, Show, HIDE, I set the gui title here
	Gui +Resize +LastFound ; +LastFound lets "Win..." commands work on the gui even though it's hidden
	If !g5
	{
		WinMove,,,,, g3, g4 ; Resize the window
		Gui, Show, x%g1% y%g2%
	}
	Else
	{
		WinMaximize ; Maximize if the window was maximized last time
		Gui, Show
	}
	OnExit GuiClose ; Use 'onexit' to make sure the gui size is saved
Return

GuiClose:
; Get the window's position and save it before the script exits.
	Gui +LastFound
	WinGet, g, MINMAX
	If !g
	{
		WinGetPos, g1, g2, g3, g4
		guiPos = %g1%,%g2%,%g3%,%g4%,0
	}
	Else If g = 1
		guiPos := SubStr( guiPos, 1, -1 ) "1"
	IniWrite %guiPos%, %scriptCfg%, Script, GuiPos
	OnExit ; We don't want this subroutine to run twice
Exitapp
It's more verbose than it could be, but you can wrap the important bits in functions (a "get"/"set" pair) if that's important to you.
User avatar
BGM
Posts: 496
Joined: 20 Nov 2013, 20:56
GitHub: bgmCoder
Contact:

Re: Perpetually growing Window

09 Dec 2013, 09:34

Thanks fellas. Lexicos - you've helped me before in the other forum. I'm glad to see you here, too!
I went with using a_guiwidth and a_guiheight - I didn't realize those were available. Thanks!
lexikos
Posts: 7088
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Perpetually growing Window

09 Dec 2013, 19:59

Lexicos isn't registered on this forum. Yet.
User avatar
BGM
Posts: 496
Joined: 20 Nov 2013, 20:56
GitHub: bgmCoder
Contact:

Re: Perpetually growing Window

09 Dec 2013, 20:10

Well, uh, sorry, I suppose I figured that lexikos is the same as Lexicos.... I reckon you are his doppleganger?
Guest

Re: Perpetually growing Window

09 Dec 2013, 22:28

It's "Lexikos" in both cases, there is no "Lexicos"...

"There can be only one" (Highlander)
Guest

Re: Perpetually growing Window

09 Dec 2013, 22:34

At least, there is no one named "Lexicos" with significant contributions...

Return to “Ask For Help”

Who is online

Users browsing this forum: AHKStudent, boiler, Saarthak Kamra, TAC109, zKade and 31 guests