autocomplex Posted October 24, 2007 Share Posted October 24, 2007 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 ... =) Want Runescape Specific Scripts and Bots?Visit AutoIt Runescape Team (ARST) forum! Link to comment Share on other sites More sharing options...
Nahuel Posted October 24, 2007 Share Posted October 24, 2007 And what's the question? You seem to have all figured out... just make it write the ini file when the window is closed with the current position... Link to comment Share on other sites More sharing options...
JustinReno Posted October 24, 2007 Share Posted October 24, 2007 You missed the question Nahuel, he wants it to write the program positions on exit or when he moves the winow, and when he starts a new window he wants it to start at the last ini position. Link to comment Share on other sites More sharing options...
autocomplex Posted October 24, 2007 Author Share Posted October 24, 2007 You missed the question Nahuel, he wants it to write the program positions on exit or when he moves the winow, and when he starts a new window he wants it to start at the last ini position.exactly ... i can't figure out how to do it ... Want Runescape Specific Scripts and Bots?Visit AutoIt Runescape Team (ARST) forum! Link to comment Share on other sites More sharing options...
JustinReno Posted October 24, 2007 Share Posted October 24, 2007 When the user pressed exit, tell it to write the program positions to the ini. The code for getting the window positions is wingetpos() Link to comment Share on other sites More sharing options...
Nahuel Posted October 24, 2007 Share Posted October 24, 2007 (edited) Try this: expandcollapse popup#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 October 24, 2007 by Nahuel Link to comment Share on other sites More sharing options...
JustinReno Posted October 24, 2007 Share Posted October 24, 2007 And if its the programs first run, you should add a default program size. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted October 25, 2007 Moderators Share Posted October 25, 2007 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 EndFuncI'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 More sharing options...
Nahuel Posted October 25, 2007 Share Posted October 25, 2007 That's awesome Smoke I've tried many times to work with GUIRegisterMsg(), but I just can't get it. I'll study that example. Link to comment Share on other sites More sharing options...
autocomplex Posted October 25, 2007 Author Share Posted October 25, 2007 (edited) Try this: expandcollapse popup#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 October 25, 2007 by inline853 Want Runescape Specific Scripts and Bots?Visit AutoIt Runescape Team (ARST) forum! Link to comment Share on other sites More sharing options...
Nahuel Posted October 25, 2007 Share Posted October 25, 2007 I gave you an idea, I won't make the script for you. You make it work the way you want. And check Smoke's code. I think it's better. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now