Lorecarver Posted September 6 Share Posted September 6 I tried this attached script to save/restore all windows on the screen and their size/position... However, it does work, except for the last window (say 2 windows are open on the screen), always moves to the upper Left corner of the screen and resizes it very small instead of leaving it in its original position. I'm running Windows 11 with autoit v3.3.16.1 What I am looking for is this: 1) a script that has a function you can: a) Be run to Save the Size and Position of all open windows on the desktop screen b) Then another function that can be run when required, to reset those windows back to their original location and size if they have moved, been resized or both. I believe the script was done by User: TomZ back in 2009 I also attached the windows.ini file the script creates of all open windows on the screen for saving the windows Positions/Sizes (I had only 2 windows open, the last one always moves to the upper left of the screen and resized very small. Any help on this is greatly appreciated! Not sure what to fix in the script or if it is because of another issue running windows 11. Save Windows Locations #2.txt windows.ini Link to comment Share on other sites More sharing options...
ioa747 Posted September 15 Share Posted September 15 That's how I would do it expandcollapse popup; https://www.autoitscript.com/forum/topic/212255-save-windows-positionsize-of-open-windows/?do=findComment&comment=1536691 #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <WinAPISysWin.au3> _CallGUI() Func _CallGUI() ; Create a GUI with two buttons: Save Setting and Restore Setting. GUICreate("Save windows position", 170, 90, -1, -1, -1, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST)) Local $ButtonSave = GUICtrlCreateButton("Save Setting", 10, 10, 150, 30) GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif") Local $ButtonRestore = GUICtrlCreateButton("Restore Setting", 10, 50, 150, 30) GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif") GUISetState(@SW_SHOW) Local $nMsg While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE ExitLoop Case $ButtonSave StoreWins() ExitLoop Case $ButtonRestore RestoreWins() ExitLoop EndSwitch WEnd Exit EndFunc ;==>_CallGUI Func StoreWins($file = "windows.ini") ; Store the positions and sizes of all visible windows Local $sPosition, $aPos Local $var = _WinAPI_EnumWindowsTop() If FileExists($file) Then FileDelete($file) For $i = 1 To $var[0][0] If IsVisible($var[$i][0]) Then $aPos = WinGetPos($var[$i][0]) $sPosition = $aPos[0] & ";" & $aPos[1] & ";" & $aPos[2] & ";" & $aPos[3] IniWrite($file, "WindowsPosition", $var[$i][0], $sPosition) EndIf Next EndFunc ;==>StoreWins Func RestoreWins($file = "windows.ini") ; Restore the positions and sizes of all windows Local $aArray = IniReadSection($file, "WindowsPosition") ; Check if an error occurred. If Not @error Then Local $aPos, $hWnd ; Read the positions and sizes of all windows from the INI file For $i = 1 To $aArray[0][0] $hWnd = HWnd($aArray[$i][0]) If WinExists($hWnd) Then $aPos = StringSplit($aArray[$i][1], ";", 2) If UBound($aPos) = 4 Then WinMove($hWnd, "", $aPos[0], $aPos[1], $aPos[2], $aPos[3]) EndIf Next EndIf EndFunc ;==>RestoreWins Func IsVisible($handle) ; Check if a window is visible Return BitAND(WinGetState($handle), 2) EndFunc ;==>IsVisible to forum how-to-post-code-on-the-forum I know that I know nothing Link to comment Share on other sites More sharing options...
Lorecarver Posted September 18 Author Share Posted September 18 @ioa747 Thank you so much! I've been so busy the last few weeks, I just saw this. I will give it a try tomorrow and see how I fair out and report back . Link to comment Share on other sites More sharing options...
Lorecarver Posted September 21 Author Share Posted September 21 @ioa747 That did it!!! Thank you gain, this helped me out alot!!! :) ioa747 1 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