Jump to content

Universal Updating Position


Recommended Posts

I made a program that is the starting point for some other applications i made. I am trying to make it so they open in the same position from an updating .ini file. So if i move the main program, the starting location in the .ini would update, and if i open another application it will start in the last location of the other application. Also if i exit and restart the application it will start in same position.

This is what i have ...

Global $StartX = IniRead("GlobalData.ini", "StartPos", "X", 0) ;<== Reads a Default Starting X Coordinate for the Ore Finder from an .Ini file.
Global $StartY = IniRead("GlobalData.ini", "StartPos", "Y", 0) ;<== ;<== Reads a Default Starting Y Coordinate for the Ore Finder from an .Ini file.
Global $x = $StartX, $y = $StartY ;<== Sets $x to $StartX so $x can later be manipulated.


    IniWrite("GlobalData.ini", "StartPos", "X", $x)
    IniWrite("GlobalData.ini", "StartPos", "Y", $y)oÝ÷ Ù8b²+-觫­¢+ÙmMÑÉÑA½Ít)`ôÔÄÈ)dôÀ

Please help me to get this to work ... =)

Link to comment
Share on other sites

Try this:

#include <GUIConstants.au3>

$X=IniRead("pos.ini","Position","X",-1)
$Y=IniRead("pos.ini","Position","Y",-1)

$Form1 = GUICreate("Form1", 331, 248, $X, $Y)
$Button1 = GUICtrlCreateButton("Create child", 63, 105, 213, 65, 0)
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            _ChildCreate()
    EndSwitch
    $WinPos=WinGetPos($Form1)
    If $WinPos[0]<>$X And $WinPos[1]<>$Y Then
        ConsoleWrite("Window Moved"&@cr)
        IniWrite("pos.ini","Position","X",$WinPos[0])
        IniWrite("pos.ini","Position","Y",$WinPos[1])
        $X=$WinPos[0]
        $Y=$WinPos[1]
    EndIf
    
WEnd


Func _ChildCreate()
    $Child= GUICreate("Form1", 100, 100, $X, $Y,-1,-1,$Form1)
    GUISetState(@SW_SHOW)


    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                GUIDelete($Child)
                ExitLoop
        EndSwitch
    WEnd
EndFunc

Run it from SciTe.

When you create the child GUI it will be created in the same postition of the parent GUI. If you move the parent and create the child again, it will do the same.

If close it, it will open in the last position.

Edited by Nahuel
Link to comment
Share on other sites

  • Moderators

I used to do this with AdlibEnable... but this thread got me thinking, so I'm going back to ... oh ... about 50 scripts and changing my method... I like this one:

Global $sMyIniLocation = "myIni.ini"
Global $nIniXPos = Int(IniRead($sMyIniLocation, 'MAINWINPOS', 'XPOS', Int(@DesktopWidth/2.5)))
Global $nIniYPos = Int(IniRead($sMyIniLocation, 'MAINWINPOS', 'YPOS', Int(@DesktopHeight/2.5)))

;Once the gui is up, move it around, then click close
_myGUI()
MsgBox(0, "", "No more gui, no let's open it again.")
_myGUI()

Func _myGUI()
    GUICreate("MOVE ME AROUND", 300, 100, $nIniXPos, $nIniYPos)
    GUIRegisterMsg(0x03, "_myWM_MOVE")
    GUISetState()
    While GUIGetMsg() <> -3
    WEnd
    GUIDelete()
    Return
EndFunc
    
Func _myWM_MOVE($hWnd, $nMsg, $wParam, $lParam)
    Local $aWPos = WinGetPos($hWnd)
    If IsArray($aWPos) Then
        IniWrite($sMyIniLocation, 'MAINWINPOS', 'XPOS', $aWPos[0])
        IniWrite($sMyIniLocation, 'MAINWINPOS', 'YPOS', $aWPos[1])
        $nIniXPos = $aWPos[0]
        $nIniYPos = $aWPos[1]
    EndIf
    Return
EndFunc
I'm not a fan of globals really... but this one does come in handy I suppose.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Try this:

#include <GUIConstants.au3>

$X=IniRead("pos.ini","Position","X",-1)
$Y=IniRead("pos.ini","Position","Y",-1)

$Form1 = GUICreate("Form1", 331, 248, $X, $Y)
$Button1 = GUICtrlCreateButton("Create child", 63, 105, 213, 65, 0)
GUISetState(@SW_SHOW)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            _ChildCreate()
    EndSwitch
    $WinPos=WinGetPos($Form1)
    If $WinPos[0]<>$X And $WinPos[1]<>$Y Then
        ConsoleWrite("Window Moved"&@cr)
        IniWrite("pos.ini","Position","X",$WinPos[0])
        IniWrite("pos.ini","Position","Y",$WinPos[1])
        $X=$WinPos[0]
        $Y=$WinPos[1]
    EndIf
    
WEnd
Func _ChildCreate()
    $Child= GUICreate("Form1", 100, 100, $X, $Y,-1,-1,$Form1)
    GUISetState(@SW_SHOW)
    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                GUIDelete($Child)
                ExitLoop
        EndSwitch
    WEnd
EndFunc

Run it from SciTe.

When you create the child GUI it will be created in the same postition of the parent GUI. If you move the parent and create the child again, it will do the same.

If close it, it will open in the last position.

BTW this only take in account that the parent can open the child. My program opens child and then exits itself, then the child can call the parent back. Its not really a parent child thing, it just a program that launches other programs, and the other programs can go back to the launcher.

Anyway ... i don't understand Smokes thing even though i tested it and it works. I don't know how to implement it, i'll try to figure it out unless somthing easier and more effiecent comes up.

Edited by inline853
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...