Sign in to follow this  
Followers 0
myspacee

Save windows position of open windows

5 posts in this topic

Hello to all,

for sure someone think to build a script that save windows position open on desktop

for later restore, but i can't find with forum search... can someone help me to find

code or some info about this task ?

thank you,

m.

Share this post


Link to post
Share on other sites



The helpfile is very helpful, first let's look into the helpfile example for the WinList() function:

$var = WinList()
For $i = 1 to $var[0][0]
  If IsVisible($var[$i][1]) Then
    MsgBox(0, "Details", "Title=" & $var[$i][0] & @LF & "Handle=" & $var[$i][1])
  EndIf
Next

Func IsVisible($handle)
  If BitAnd( WinGetState($handle), 2 ) Then 
    Return 1
  Else
    Return 0
  EndIf
EndFunc

This code will allow you to loop through all VISIBLE windows. You must then obtain position and dimensions from those windows. This can be done with the WinGetPos function. This function returns an array containing this information. Next, we need to store the positions, I reccommend you to use the IniWrite functions for this.

To restore the windows, you must use the WinList function again, combined with IniRead and WinSetPos.

Share this post


Link to post
Share on other sites

thank you for reply Tomz,

i've already done my running code, but search one script built by skilled coder than me muttley

have different problems in wingetpos (eg: value -32000 for some windows, etc...)

so i ask if problem was never take before by someone,

m.

Share this post


Link to post
Share on other sites

This would be my way of doing it:

StoreWins()
Sleep(5000)
RestoreWins()

Func StoreWins($file = "windows.ini")
    Local $var = WinList()
    If FileExists($file) Then FileDelete($file)
    For $i = 1 to $var[0][0]
      If IsVisible($var[$i][1]) Then
        Local $pos = WinGetPos($var[$i][1])
        IniWrite($file, Binary($var[$i][0]), "x", $pos[0])
        IniWrite($file, Binary($var[$i][0]), "y", $pos[1])
        IniWrite($file, Binary($var[$i][0]), "w", $pos[2])
        IniWrite($file, Binary($var[$i][0]), "h", $pos[3])
      EndIf
    Next
EndFunc

Func RestoreWins($file = "windows.ini")
    Local $var = WinList()
    For $i = 1 to $var[0][0]
      If IsVisible($var[$i][1]) Then
        If IniRead($file, $var[$i][0], "x", False) Then
            Local $pos = WinGetPos($var[$i][1])
            WinMove($var[$i][0], "", IniRead($file, Binary($var[$i][0]), "x", $pos[0]), IniRead($file, Binary($var[$i][0]), "y", $pos[1]), IniRead($file, Binary($var[$i][0]), "w", $pos[2]), IniRead($file, Binary($var[$i][0]), "h", $pos[3]))
        EndIf
      EndIf
    Next
EndFunc

Func IsVisible($handle)
    Return BitAnd(WinGetState($handle), 2)
EndFunc

Share this post


Link to post
Share on other sites

nice and simple,

modifing it for my office use...

thank you again,

m

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  
Followers 0