 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Cracked-Nut
Joined: 04 Mar 2006 Posts: 3
|
Posted: Sat Mar 04, 2006 4:40 pm Post subject: GUI-window positioning |
|
|
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.
| Code: | 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.
* Sorry about the bad english but i speak Dutch, i hope u understand * 
Last edited by Cracked-Nut on Sat Mar 04, 2006 4:56 pm; edited 1 time in total |
|
| Back to top |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 5382 Location: /b/
|
Posted: Sat Mar 04, 2006 4:44 pm Post subject: |
|
|
Don't forget A_ScreenWidth and A_ScreenHeight which are the built-in variables containing the screen resolution values. _________________
 |
|
| Back to top |
|
 |
Cracked-Nut
Joined: 04 Mar 2006 Posts: 3
|
Posted: Sat Mar 04, 2006 4:56 pm Post subject: |
|
|
Sorry, i forgot to put the code in my post.
Here it is.  |
|
| Back to top |
|
 |
bLisTeRinG
Joined: 15 Nov 2004 Posts: 45 Location: Warrnambool
|
Posted: Mon Mar 06, 2006 6:24 am Post subject: Me too! |
|
|
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:
| Code: | 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:
| Code: | | Gui, Show, %regWPos%,%regFName% >>> %Title% |
And at exit/close etc:
| Code: | 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:
| Code: | GuiSize:
If A_EventInfo = 1
Return
GuiControl, Move, deClick, % "W" . (A_GuiWidth - 20) . " H" . (A_GuiHeight - 90)
Return
|
gq. |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|