Jump to content
Sign in to follow this  

last position slides

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>
$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))
While 1
    $msg = GUIGetMsg()
    Dim $G, $C
    $G = WinGetPos($Gui)
    $C = ControlGetPos($Gui, "", $Combo)
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop

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])

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

Share this post

Link to post
Share on other sites

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.

Share this post

Link to post
Share on other sites


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


$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)
$iButton = GUICtrlCreateButton("MyButton", $aWGP[2] - 88, $aWGP[3] - 55, 80, 20)
GUISetState(@SW_SHOW, $hGui)

GUIRegisterMsg($WM_MOVE, "WM_MOVE")
GUIRegisterMsg($WM_SIZE, "WM_MOVE")

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
        Case $iCombo
            ;;; Do whatever
        Case $iButton
            ;;; Do whatever

Func WM_MOVE($hWnd, $Msg, $wParam, $lParam)
    If Not BitAND(WinGetState($hGui), 16) And Not BitAND(WinGetState($hGui), 32) Then $aWGP = WinGetPos($hGui)
EndFunc   ;==>WM_MOVE

Func LoadPos()
    For $i = 0 To UBound($aWGP) - 1
        $aWGP[$i] = IniRead($Ini, "Section", $i, $aWGP[$i])
EndFunc   ;==>LoadPos

Func SavePos()
    For $i = 0 To UBound($aWGP) - 1
        IniWrite($Ini, "Section", $i, $aWGP[$i])
EndFunc   ;==>SavePos


Edited by smashly

Share this post

Link to post
Share on other sites

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 ;)

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  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.