twelo Posted December 17, 2009 Share Posted December 17, 2009 i made a gui with some controls, i want to save position in ini for reopen to last position #include <GUIConstants.au3> #include <EditConstants.au3> #include <WindowsConstants.au3> #include <GUIComboBox.au3> Opt("OnExitFunc","Pos") $Gui = GUICreate("MyGui", iniread("my.ini", "Section", "W-Pos", 300), iniread("my.ini", "Section", "H-Pos", 60), iniread("my.ini", "Section", "X-Pos", -1), iniread("my.ini", "Section", "Y-Pos", -1), BitOR($WS_MAXIMIZEBOX,$WS_MINIMIZEBOX,$WS_SIZEBOX)) $Combo = GUICtrlCreateCombo("MyCombo", iniread("my.ini", "Section", "COMBO-X", 8), iniread("my.ini", "Section", "COMBO-Y", 8), iniread("my.ini", "Section", "COMBO-W", 285), iniread("my.ini", "Section", "COMBO-H", 25)) GUISetState() While 1 $msg = GUIGetMsg() Dim $G, $C $G = WinGetPos($Gui) $C = ControlGetPos($Gui, "", $Combo) If $msg = $GUI_EVENT_CLOSE Then ExitLoop Wend func Pos() iniwrite("my.ini", "Section", "X-Pos", $G[0]) iniwrite("my.ini", "Section", "Y-Pos", $G[1]) iniwrite("my.ini", "Section", "W-Pos", $G[2]) iniwrite("my.ini", "Section", "H-Pos", $G[3]) iniwrite("my.ini", "Section", "COMBO-X", $C[0]) iniwrite("my.ini", "Section", "COMBO-Y", $C[1]) iniwrite("my.ini", "Section", "COMBO-W", $C[2]) iniwrite("my.ini", "Section", "COMBO-H", $C[3]) EndFunc problem is every time gui sliding extra to the right & down side when reopen run the script close, dont move mouse then run script again & again u will see the difference how to fix it ? and any way to do the last position thing with gui & all child window controls with a single command or script ? above i did separate settings for gui & combo sory bad english Link to comment Share on other sites More sharing options...
danielkza Posted December 18, 2009 Share Posted December 18, 2009 IIRC, WinGetPos returns the size of the window *including* title bar and borders, while GUICreate takes them as client coordinates, that *do not* account for the aforementioned extra elements.You can retrieve the window info in the proper client coordinates using GetClientRect. Link to comment Share on other sites More sharing options...
smashly Posted December 18, 2009 Share Posted December 18, 2009 (edited) Hi, Another way maybe you can set the resizing mode for the controls so they stay where you want when the gui is resized. This way you only need to worry about the Gui position and Size and you can let the Gui worry about keeping the controls where they are meant to be.expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt("OnExitFunc", "SavePos") Global $Ini = @ScriptDir & "\my.ini" Global $aWGP[4] = [-1, -1, 300, 100] Global $hGui, $iCombo, $iButton, $Msg LoadPos() $hGui = GUICreate("MyGui", $aWGP[2], $aWGP[3], $aWGP[0], $aWGP[1], BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SIZEBOX)) $iCombo = GUICtrlCreateCombo("MyCombo", 8, 8, 285, 25) GUICtrlSetResizing(-1, BitOR($GUI_DOCKLEFT, $GUI_DOCKTOP, $GUI_DOCKSIZE)) $iButton = GUICtrlCreateButton("MyButton", $aWGP[2] - 88, $aWGP[3] - 55, 80, 20) GUICtrlSetResizing(-1, BitOR($GUI_DOCKRIGHT, $GUI_DOCKBOTTOM, $GUI_DOCKSIZE)) GUISetState(@SW_SHOW, $hGui) GUIRegisterMsg($WM_MOVE, "WM_MOVE") GUIRegisterMsg($WM_SIZE, "WM_MOVE") While 1 $Msg = GUIGetMsg() Switch $Msg Case $GUI_EVENT_CLOSE Exit Case $iCombo ;;; Do whatever Case $iButton ;;; Do whatever EndSwitch WEnd Func WM_MOVE($hWnd, $Msg, $wParam, $lParam) If Not BitAND(WinGetState($hGui), 16) And Not BitAND(WinGetState($hGui), 32) Then $aWGP = WinGetPos($hGui) Return $GUI_RUNDEFMSG EndFunc ;==>WM_MOVE Func LoadPos() For $i = 0 To UBound($aWGP) - 1 $aWGP[$i] = IniRead($Ini, "Section", $i, $aWGP[$i]) Next EndFunc ;==>LoadPos Func SavePos() For $i = 0 To UBound($aWGP) - 1 IniWrite($Ini, "Section", $i, $aWGP[$i]) Next EndFunc ;==>SavePos Cheers Edited December 18, 2009 by smashly Link to comment Share on other sites More sharing options...
twelo Posted December 18, 2009 Author Share Posted December 18, 2009 thanks guys i got it to work with "wingetpos" & "winmove" command sliding fixed & short single script for main window & all its child controls works fantastic 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