Jump to content

Saving GUI window position


MarioX
 Share

Recommended Posts

I had made lot's of search but nothing found...

I'm a AutoIt beginner, until now all the GUI I had made was centered on screen using @DesktopHeight and @DesktopWidth.

Now I want made a GUI that remember the last desktop position at next restart.

Is this a Windows feature or some coding is required ?

Thanks for any help!

Mario

Link to comment
Share on other sites

I had made lot's of search but nothing found...

I'm a AutoIt beginner, until now all the GUI I had made was centered on screen using @DesktopHeight and @DesktopWidth.

Now I want made a GUI that remember the last desktop position at next restart.

Is this a Windows feature or some coding is required ?

Thanks for any help!

Mario

Requires code. Just use an INI file, get the position and store it into the INI before to close the GUI. Of course, the script need to read this values for X and Y when is displayed the next time.
Link to comment
Share on other sites

you need some coding and maybe an ini-file

Opt("OnExitFunc","OnAutoItExit")
guicreate("gui", 300, 300, iniread("some.ini", "Section", "X-Pos", 0), iniread("some.ini", "Section", "Y-Pos", 0)); this will put your window to the last stored coordinates (default: 0/0)
func OnAutoItExit()
$a = wingetpos("your win")
iniwrite("some.ini", "Section", "X-Pos", $a[0])
iniwrite("some.ini", "Section", "Y-Pos", $a[1])

hope this helps

Link to comment
Share on other sites

Following the Nuffilein805 suggested code, I've made the following, but something goes wrong when it's time to store the window position in the .ini file

I always get the following value:

[Position]

X-Pos=-4

Y-Pos=-4

It seem that WinGetPos don't read the Gui value

I've forced WinGetPos to read the Gui using the following:

$a = WinGetPos("gui")

But I get a "Subscript used with non-Array variable" error.

#include <GUIConstants.au3>

Opt("OnExitFunc","OnAutoItExit")
; this will put your window to the last stored coordinates (default: 0/0)
guicreate("gui", 300, 300, iniread("GuiPosition.ini", "Position", "X-Pos", 0), iniread("GuiPosition.ini", "Position", "Y-Pos", 0))
GUISetState (@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend


func OnAutoItExit()
    $a = WinGetPos("")
    IniWrite("GuiPosition.ini", "Position", "X-Pos", $a[0])
    IniWrite("GuiPosition.ini", "Position", "Y-Pos", $a[1])
EndFunc

What's wrong ?

Edited by MarioX
Link to comment
Share on other sites

you're right it doesn't get the gui, because it is already closed

1 found a way to walk around

#include<guiconstants.au3>
Opt("OnExitFunc","OnAutoItExit")
guicreate("gui", 300, 300, iniread("some.ini", "Section", "X-Pos", 0), iniread("some.ini", "Section", "Y-Pos", 0)); this will put your window to the last stored coordinates (default: 0/0)
GUISetState()
While 1
    $msg = GUIGetMsg()
    dim $a
    $a = wingetpos("gui")
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend

func OnAutoItExit()
iniwrite("some.ini", "Section", "X-Pos", $a[0])
iniwrite("some.ini", "Section", "Y-Pos", $a[1])
EndFunc

this should work

at least it does at my pc

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...