Sign in to follow this  
Followers 0
AutoCraig

Retain Previous Window Position

7 posts in this topic

I have a script that will prompt the user with multiple windows (FileSelectFolder, MsgBox, InputBox, etc.). I've been trying to figure out a way that if the user moves the first window anywhere other than center, then continues through the script, I want the next window(s)to come up in the same place the last one left off. I tried to use WinGetPos but it needs the title of the window which will close before it is able to get any position or title. Please help! Thanks!

Share this post


Link to post
Share on other sites



When the user goes to close a window, before you exit or exitloop, write the value in and INI file. The first section should go at the beginning of the script to create an INI file if it does not exist. The second part write the window position to the INI. From there all you have to do is read the INI for last used values.

If NOT FileExists(@TempDir & "\data.ini") Then
_FileCreate(@TempDir & "\data.ini")
FileWrite(@TempDir & "\data.ini", "[WinPosition]" & @CRLF)
$x = @DesktopWidth / 2 - 100
FileWrite(@TempDir & "\data.ini", "X=" & $x & @CRLF)
$y = @DesktopHeight / 2 - 33
FileWrite(@TempDir & "\data.ini", "Y=" & $y & @CRLF)
EndIf

;.....

$size = WinGetPos("My Gui Window", "")
$x = $size[0] 
$y = $size[1] 
IniWrite(@TempDir & "\data.ini", "WinPosition", "X", $x)
IniWrite(@TempDir & "\data.ini", "WinPosition", "Y", $y)

#include <ByteMe.au3>

Share this post


Link to post
Share on other sites

Thanks for the response. I think this would work if I were creating my own GUI windows but I'm using the MsgBox, FileSelectFolder, functions which don't have coordinates flags. Also, how would I get the title of the AutoIt window that pops up when it closes before something like WinGetPos would execute?

FileSelectFolder("My Gui Window", ...)
;Window would close here
$size = WinGetPos("My Gui Window", "")

This wouldn't be able to get the FileSelectFolder position.

Share this post


Link to post
Share on other sites

Thanks for the response. I think this would work if I were creating my own GUI windows but I'm using the MsgBox, FileSelectFolder, functions which don't have coordinates flags. Also, how would I get the title of the AutoIt window that pops up when it closes before something like WinGetPos would execute?

FileSelectFolder("My Gui Window", ...)
;Window would close here
$size = WinGetPos("My Gui Window", "")

This wouldn't be able to get the FileSelectFolder position.

#include <timers.au3>

Global $wp

$t1 = _Timer_SetTimer(0,30,"checkpos")


msgbox(262144,"move me", "anywhere")


msgbox(262144,"you move msgbox to", "X = " & $wp[0] & ', y= ' & $wp[1])


func checkpos($a, $b,$c,$d)
    #forceref $a,$b,$c,$d

    $wp = wingetpos("move me")
EndFunc

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

This is good and it would work but I can't give coordinates to msgbox. Thanks for the help!

You canusing the method I showed, and you can also make your own little message box so I think you give up rather easily.

#include <timers.au3>

Global $wp

$t1 = _Timer_SetTimer(0, 30, "checkpos")


MsgBox(262144, "move me", "anywhere")
_Timer_KillAllTimers(0)

$t1 = _Timer_SetTimer(0, 30, "setposB")
MsgBox(262144, "you moved msgbox to", "here " & $wp[0] & ', ' & $wp[1] & @CRLF & "(after flicker?")

msgboxpos("some message", "no flicker", $wp[0], $wp[1])

Func checkpos($a, $b, $c, $d)
    #forceref $a,$b,$c,$d
    If WinExists("move me") Then
        $wp = WinGetPos("move me")
    EndIf

EndFunc   ;==>checkpos


Func setposB($a, $b, $c, $d)
    #forceref $a,$b,$c,$d
    If WinExists("you moved msgbox to") Then
        WinMove("you moved msgbox to", "", $wp[0], $wp[1])
        ConsoleWrite("ytcfhtfch" & @CRLF)
        _Timer_KillAllTimers(0)
    EndIf

EndFunc   ;==>setposB

Func msgboxpos($text, $title, $topx, $topy)

    $g = GUICreate($title, 200, 100, $topx, $topy)
    $lab = GUICtrlCreateLabel($text, 20, 30)
    $b = GUICtrlCreateButton("OK", 80, 70)
    GUISetState()

    While 1

        $msg = GUIGetMsg()
        If $msg = -3 Then ExitLoop
        If $msg = $b Then ExitLoop
    WEnd

    GUIDelete($g)
EndFunc   ;==>msgboxpos

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Cool that worked! Thanks a lot!

Share this post


Link to post
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
Sign in to follow this  
Followers 0