Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

GUI-window positioning


  • Please log in to reply
4 replies to this topic
Cracked-Nut
  • Members
  • 3 posts
  • Last active: Mar 04 2006 09:22 PM
  • Joined: 04 Mar 2006
I had a problem. My GUI-window was positioned on MY resolution 1024*768. But on a 1600*1200 screen it had another position because it's not the same resolution.

I was thinking about a solution, and found INIRead and INIWrite. Now, the user can position the GUI like he wants it, if the GUI closes it saves the positioning and the width and the height, and if it starts, it reads the saved information and the GUI comes back like it was before. :)

IniRead, posx, inf.ini, pos, x
IniRead, posy, inf.ini, pos, y
IniRead, height, inf.ini, pos, height
IniRead, width, inf.ini, pos, width
Gui, Add, Some gui stuff...........
Gui, Show, x%posx% y%posy% h%height% w%width%, title of your gui here
Return

GuiClose:
WinGetPos, posx, posy, width, height, title of your gui,
IniWrite, %posx%, inf.ini, pos, x
IniWrite, %posy%, inf.ini, pos, y 
IniWrite, %width%, inf.ini, pos, width
IniWrite, %height%, inf.ini, pos, height
ExitApp ;If window closes, WinGetPos gathers information about the window and saves it into an .INI-file

I found this solution soo great, that i want to share it with everyone. :)
:oops: * Sorry about the bad english but i speak Dutch, i hope u understand * :oops:

polyethene
  • Members
  • 5519 posts
  • Last active: May 17 2015 06:39 AM
  • Joined: 26 Oct 2012
Don't forget A_ScreenWidth and A_ScreenHeight which are the built-in variables containing the screen resolution values.

autohotkey.com/net Site Manager

 

Contact me by email (polyethene at autohotkey.net) or message tidbit


Cracked-Nut
  • Members
  • 3 posts
  • Last active: Mar 04 2006 09:22 PM
  • Joined: 04 Mar 2006
Sorry, i forgot to put the code in my post.
Here it is. :-)

bLisTeRinG
  • Members
  • 45 posts
  • Last active: Nov 07 2012 11:15 AM
  • Joined: 15 Nov 2004
In another burst of synchronicity (or coincidence) I was just cursing over my Gui Window. It kept expanding each time I closed, the opened it again. It wasn't the saving (at exit) or the recovery (at open). My Gui just did it all on its own. So I ended up estimating the error and subtracting it. A "fix" rather than a solution. Otherwise it works well on my 98SE+. Notice how the (cumbersome) adding is done; I just couldn't do the math. It worked as a scriptlet with var+=n but as soon as I put it into my script it came up blank. ??? Any Clues?

So here are the relevant bits, good hacking.

This is in the opening section:
RegRead, regWPos, HKLM, Software\bLisTeRinG\RegFileEd, WinPosition
If regWPos=
regWPos=x60 y180 w600 h200
Loop, Parse, regWPos, %A_Space%
{
y = %A_LoopField%
StringTrimLeft, y, y, 1
If A_Index < 3
{
y += 20
x%A_Index% = %y%
}
Else
{
x%A_Index% = %y%
}
}
regXpos=x%x1% y%x2% w%x3% h%x4%
;msgbox, 4096,,regXpos:%regXpos%`n%x1%`n%x2%`n%x3%`n%x4%
RegWrite, REG_SZ, HKLM, Software\bLisTeRinG\RegFileEd, WinPosition, %regXpos%
;Yes yes add some resolution checking with A_ScreenWidth A_ScreenHeightregXpos=
x=
y=
x1=
x2=
x3=
x4=

Then when the window is displayed:
Gui, Show, %regWPos%,%regFName% >>> %Title%

And at exit/close etc:
GuiClose:
GuiEscape:
WinGetPos, regW1, regW2, regW3, regW4, A
regW3 -= 12
regW4 -= 32
regWpos=x%regW1% y%regW2% w%regW3% h%regW4%
RegWrite, REG_SZ, HKLM, Software\bLisTeRinG\RegFileEd, WinPosition, %regWPos%
ExitApp

I also found the following useful bit somewhere. I barely understand it, and it never works when I try it; but it really works:

GuiSize:
If A_EventInfo = 1
Return
GuiControl, Move, deClick, % "W" . (A_GuiWidth - 20) . " H" . (A_GuiHeight - 90)
Return

gq.

kiwichick
  • Members
  • 48 posts
  • Last active: Jul 25 2018 08:01 AM
  • Joined: 02 Jan 2014

Hi there, I know this is an old thread but, since my question is directly related to Cracked-Nut's script, I didn't know whether to start a new thread or not. I have tried this script but it doesn't work properly.

 

Am I right in thinking the height and width dimensions that are saved are 'Window' dimensions whereas the script creates 'GUI' dimensions which don't include window border and titlebar. I ask because the saved height and width dimensions are increased by 28 and 6 respectively each time the window is closed, so whenever the window is re-opened it's a little bit bigger.

 

For example, if the ini file has height=200 and width=200, when the script is run the window opens with 'GUI' that size (but not the entire 'Window') and if closed without making any change to window size or position the ini is updated to height=228 and width=206. Next time height=256 and width=212 and so on open each launch of the script.

 

So I was thinking I could add some maths to the script and make a 28 and 6 subtraction before the dimensions are saved but I thought I would post here first in case there is an easier solution, or different code I can use.

 

Cheers :-)