Jump to content

last position slides


twelo
 Share

Recommended Posts

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

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.

#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 by smashly
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...