Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Save and Restore window sizes & positions


  • Please log in to reply
3 replies to this topic
cranky
  • Members
  • 3 posts
  • Last active: Sep 21 2011 12:44 PM
  • Joined: 20 Mar 2010
Hi all. I dunno if this has been done already. I wanted something
that would save & restore the sizes & positions of all windows,
because sometimes I need to drop the screen res to run certain
games, and when I go back to my normal res, all open windows
have been resized/moved to fit the smaller screen.
Expose.ahk by keyboardfreak gave me a starting point.

winsave.ahk:
;**************************************
;** store window sizes & positions
;
;   usage: 
;      to save window sizes & positions, call "WinSave.ahk"
;      to restore window sizes & positions, call "WinRestore.ahk"
;
;   incorporates code from "expose.ahk" by "keyboardfreak"
;      http://www.autohotkey.com/forum/topic1090.html
;
; @version 1.0 cranky 20-Mar-2010; tested on Win XP SP2
;**************************************

#SingleInstance force

;SetTitleMatchMode:
;  1 = starts with
;  2 = contains 
;  3 = exact
SetTitleMatchMode, 2

; global variables
NumWindows = 0
active_window = 0

; global constants
spaces  := "                 "
gDebug = 0 ; set to 1 to enable debug output (DebugView etc)
movetime = 700 ; time for a window to resize / minimize / maximize

;**********************************
;** store window sizes & positions; 
;   shink to fit a small screen 
;**********************************

If gDebug
{
	OutputDebug, **** winsave.ahk ****

	; format a header for debug output, 
	; with fixed-width columns:
	StringLeft, padding, spaces, (12 - StrLen("IDX"))
	msg := "IDX" . padding . A_tab . "| "  

	StringLeft, padding, spaces, (8 - StrLen("MinMax"))
	msg := msg . "MinMax" . padding . A_tab . "| "

	StringLeft, padding, spaces, (8 - StrLen("XPOS"))
	msg := msg . padding . "XPOS" . ","
	StringLeft, padding, spaces, (8 - StrLen("YPOS"))
	msg := msg . padding . "YPOS" . A_tab . "| "

	StringLeft, padding, spaces, (8 - StrLen("WIDTH"))
	msg := msg . padding . "WIDTH" . ","
	StringLeft, padding, spaces, (8 - StrLen("HEIGHT"))
	msg := msg . padding . "HEIGHT" . A_tab . "| "

	msg := msg . "TITLE"

	OutputDebug, %msg%
}
Else
{
	BlockInput, On
}

datafile = %A_Temp%\$winsave$.tmp
If FileExist(datafile)
	FileDelete, %datafile%

msg := "# temp file for WinSave.ahk and WinRestore.ahk" . Chr(13) . Chr(10)
FileAppend, %msg%, %datafile%

;** enumerate all windows with titles:
;
WinGet, IDs, List, , , Program Manager
Loop, %IDs%
{
	StringTrimRight, id, IDs%a_index%, 0
	WinGetTitle, title, ahk_id %id%

	; don't add windows with empty titles
	If title =
		Continue

	numwindows += 1

	; store the index of the active window
	IfWinActive, ahk_id %id%
		active_window = %id%

	WinGet, IsMinMax, MinMax, ahk_id %id%
	If IsMinMax <> 0
	{
		WinRestore, ahk_id %id%
		Sleep, %movetime%
	}

	WinGetPos, x, y, wid, hgt, ahk_id %id%

	If gDebug
	{
		; format a line for debug output, 
		; with fixed-width columns:
		StringLeft, padding, spaces, (12 - StrLen(id))
		msg := id . padding . A_tab . "| "  

		StringLeft, padding, spaces, (8 - StrLen(IsMinMax))
		msg := msg . IsMinMax . padding . A_tab . "| "

		StringLeft, padding, spaces, (8 - StrLen(x))
		msg := msg . padding . x . ","
		StringLeft, padding, spaces, (8 - StrLen(y))
		msg := msg . padding . y . A_tab . "| "

		StringLeft, padding, spaces, (8 - StrLen(wid))
		msg := msg . padding . wid . ","
		StringLeft, padding, spaces, (8 - StrLen(hgt))
		msg := msg . padding . hgt . A_tab . "| "

		msg := msg . title

		OutputDebug,  %msg%
	}

	; store window id, position & size as a formatted string:
	fields = %id%#%IsMinMax%#%x%#%y%#%wid%#%hgt%

	fields := fields . Chr(13) . Chr(10)
	FileAppend, %fields%, %datafile%

;	; (TEST) shrink the window
;	WinMove, ahk_id %id%, , 0, 0, 500, 400
;	Sleep, %movetime%

	If (IsMinMax < 0)
	{
		WinMinimize, ahk_id %id%
		Sleep, %movetime%
	}
	Else If (IsMinMax > 0)
	{
		WinMaximize, ahk_id %id%
		Sleep, %movetime%
	}
}

If active_window <> 0
	WinActivate, ahk_id %active_window%

BlockInput, Off
Exit ;

winrestore.ahk:
;**************************************
;** restore windows to original size & position
;
;   usage: 
;      to save window sizes & positions, call "WinSave.ahk"
;      to restore window sizes & positions, call "WinRestore.ahk"
;
;   incorporates code from "expose.ahk" by "keyboardfreak"
;      http://www.autohotkey.com/forum/topic1090.html
;
; @version 1.0 cranky 20-Mar-2010; tested on Win XP SP2
;**************************************

#SingleInstance force

;SetTitleMatchMode:
;  1 = starts with
;  2 = contains 
;  3 = exact
SetTitleMatchMode, 2

; global variables
NumWindows = 0
active_window = 0

; global constants
spaces  := "                 "
gDebug = 0 ; set to 1 to enable debug output (DebugView etc)
movetime = 700 ; time for a window to resize / minimize / maximize

;**********************************
;** restore windows to original size & position
;**********************************

If gDebug
{
	OutputDebug, **** winrestore.ahk ****

	; format a header for debug output, 
	; with fixed-width columns:
	StringLeft, padding, spaces, (12 - StrLen("IDX"))
	msg := "IDX" . padding . A_tab . "| "  

	StringLeft, padding, spaces, (8 - StrLen("MinMax"))
	msg := msg . "MinMax" . padding . A_tab . "| "

	StringLeft, padding, spaces, (8 - StrLen("XPOS"))
	msg := msg . padding . "XPOS" . ","
	StringLeft, padding, spaces, (8 - StrLen("YPOS"))
	msg := msg . padding . "YPOS" . A_tab . "| "

	StringLeft, padding, spaces, (8 - StrLen("WIDTH"))
	msg := msg . padding . "WIDTH" . ","
	StringLeft, padding, spaces, (8 - StrLen("HEIGHT"))
	msg := msg . padding . "HEIGHT" . A_tab . "| "

	msg := msg . "TITLE"

	OutputDebug, %msg%
}
Else
{
	BlockInput, On
}

; save active window
WinGet, IDs, List, , , Program Manager
Loop, %IDs%
{
	StringTrimRight, id, IDs%a_index%, 0
	; store the index of the active window
	IfWinActive, ahk_id %id%
		active_window = %id%
}

datafile = %A_Temp%\$winsave$.tmp
If FileExist(datafile)
{
	; continue
}
Else
{
	MsgBox, Error: cannot find %datafile%
	BlockInput, Off
	Exit
}

; restore window size & position
;
Loop, Read, %datafile%
{
	If gDebug
		OutputDebug, ---- A_LoopReadLine = %A_LoopReadLine%
	
	StringLeft, c1, A_LoopReadLine, 1
	If (c1 = "#")
		Continue ;

	StringSplit, windata, A_LoopReadLine,#

	StringTrimLeft, id,     windata1, 0
	StringTrimLeft, minmax, windata2, 0
	StringTrimLeft, x,      windata3, 0
	StringTrimLeft, y,      windata4, 0
	StringTrimLeft, wid,    windata5, 0
	StringTrimLeft, hgt,    windata6, 0

	If ErrorLevel
	{
		MsgBox, Error reading %datafile%
		BlockInput, Off
		Exit
	}

	If gDebug
	{
		; format a line for debug output, 
		; with fixed-width columns:
		StringLeft, padding, spaces, (12 - StrLen(id))
		msg := id . padding . A_tab . "| "  

		StringLeft, padding, spaces, (8 - StrLen(minmax))
		msg := msg . minmax . padding . A_tab . "| "

		StringLeft, padding, spaces, (8 - StrLen(x))
		msg := msg . padding . x . ","
		StringLeft, padding, spaces, (8 - StrLen(y))
		msg := msg . padding . y . A_tab . "| "

		StringLeft, padding, spaces, (8 - StrLen(wid))
		msg := msg . padding . wid . ","
		StringLeft, padding, spaces, (8 - StrLen(hgt))
		msg := msg . padding . hgt . A_tab . "| "

		msg := msg . "(title)"

		OutputDebug,  %msg%
	}

	WinGet, procID, PID, ahk_id %id%
	If procID = 0
	{
		; this window has been closed 
		; since running WinSave; ignore:
		Continue ;
	}

	WinGet, IsMinMax, MinMax, ahk_id %id%
	If IsMinMax <> 0
	{
		WinRestore, ahk_id %id%
		Sleep, %movetime%
	}

	WinMove, ahk_id %id%, , %x%, %y%, %wid%, %hgt%
	Sleep, %movetime%

	If (minmax < 0)
	{
		WinMinimize, ahk_id %id%
		Sleep, %movetime%
	}
	Else If (minmax > 0)
	{
		WinMaximize, ahk_id %id%
		Sleep, %movetime%
	}
}

FileDelete, %datafile%

If active_window <> 0
	WinActivate, ahk_id %active_window%

BlockInput, Off
Exit ;

Here's a use case - running Need For Speed SHIFT (the free demo version)
(game needs screen res to match game res for stability)

nfs-shift-run.ahk:
;**************************************
;** run a game with special screen resolution
; @version 1.0 cranky March 20, 2010
;**************************************
#SingleInstance ignore

;** wait until system is ready:
WinWait, Program Manager, 
IfWinNotActive, Program Manager, , WinActivate, Program Manager, 
WinWaitActive, Program Manager, 

;** store window sizes & positions
RunWait, winsave.ahk

;** set screen to selected res (using RivaTuner / Launcher hotkey):
Sleep, 1000
Send, {ALTDOWN}{CTRLDOWN}5{ALTUP}{CTRLUP}

;** run game:
Sleep, 1000
Run, C:\Games\Need For Speed - SHIFT demo\shiftdemo.exe, C:\Games\Need For Speed - SHIFT demo, ,NewPID

;** allow mouse & controllers to have more priority than game: 
Sleep, 1000
Process, priority, %NewPID%, BelowNormal 

;** wait for game to close:
Process, WaitClose, %NewPID% 

;** return screen to normal res (using RivaTuner / Launcher hotkey):
Sleep, 1000
Send, {ALTDOWN}{CTRLDOWN}3{ALTUP}{CTRLUP}

;** restore windows to original size & position
Sleep, 1000
RunWait, winrestore.ahk
Sleep, 1000
Exit ;
...note use of RivaTuner & it's launcher hotkeys to quickly change screen resolution.
nfs-shift-run.ahk assumes WinSave.ahk & WinRestore.ahk can be found in the current dir, or the PATH.

winsave.ahk creates a file in %temp% called $winsave$.tmp, which is deleted by winrestore.ahk

Hope some of you find this useful! Please test on Win 7 for me!

emo1313
  • Members
  • 1 posts
  • Last active: May 07 2010 01:38 AM
  • Joined: 06 May 2010
super awsome-tastic.
i been lookin for something to do this very thing for some time now. I am seeing if I can modify it a little so that it will open the programs in the list if they are not currently open.
I have a couple computers on my network that are headless that I access only from remote desktop.
being able to log in, load and place all the apps i want in the correct locations with a single click would be extremely useful. would be a great time saver getting my work space exactly the way i want and expect it to be, especially if i set it to start at login.
awsome work!,well done

cranky
  • Members
  • 3 posts
  • Last active: Sep 21 2011 12:44 PM
  • Joined: 20 Mar 2010
ThankyouThankyou. You've got an interesting application. This script indexes by proc ID, but you will prob want to index by exe name or window title. Good luck! Post your working script please!

soggos
  • Members
  • 129 posts
  • Last active: Nov 30 2012 10:35 AM
  • Joined: 27 Mar 2008
i like it

My way for save size/position of each Open Folders
(Note: in explorer option 'path in the title' must be actived)
;	=========================================================== %		SESSION_DOSSIER_SAUVER.ahk
;	=========================================================== % le fichier doivent porter l'extension ;ses
;	=========================================================== %
; #NAME>	SESSION_DOSSIER_SAUVER.ahk							; cause can run standAlone
;	=========================================================== %
; (Note: in explorer option path in the title must be actived)
; A way for save  size/position each Open Folders in textFile.ses
;

	SESSION_DOSSIER_SAUVER:
	if data_file=
		data_file = %A_ScriptDir%\win_save.ses
		
	; Gui +LastFoundExist
	Gui +OwnDialogs  			; Force the user to dismiss the FileSelectFile dialog before returning to the main window.
	FileSelectFile, OutputVar, 16, %data_file%, SAUVER la SESSION de DOSSIER dans un fichier de session, *.ses
	if OutputVar=
		{
		IfInString , A_ScriptName, SESSION_DOSSIER_SAUVER	; script sans console
		ExitApp												; donc refermer
		Else
		Return
		}
	TrayTip , SAUVEGARDE session Dossier, en cours
	SplitPath , OutputVar, name, dir, ext, name_no_ext, drive	; To fetch all info:
	if ext<>ses
			data_file=%OutputVar%.ses
			Else
			data_file=%OutputVar%
	If FileExist(data_file)
	   FileDelete, %data_file%

WinGet, IDs, List, , , Program Manager
Loop, %IDs%
	{
	StringTrimRight, id, IDs%a_index%, 0
	WinGetTitle, title, ahk_id %id%

	; only existan folder
	IfNotExist %title%
		continue	
	FileGetAttrib , attrib , %title%
	IfNotInString , attrib ,D
		Continue
	
	WinGet, IsMinMax, MinMax, ahk_id %id%
	If IsMinMax <> 0
	WinRestore, ahk_id %id%
		
	WinGetPos, x, y, w, h, ahk_id %id%

	fields= %title%|%x%|%y%|%w%|%h%`n
	FileAppend, %fields%, %data_file%

	
	; remettre
	   If (IsMinMax < 0)
	   {
		  WinMinimize, ahk_id %id%
	   }
	   Else If (IsMinMax > 0)
	   {
		  WinMaximize, ahk_id %id%
	   }
	   
	}
	TrayTip
	
		IfInString , A_ScriptName, SESSION_DOSSIER_SAUVER	; script sans console
		ExitApp												; donc refermer
Return
; ===============
;	=========================================================== %
; #END of > NAME>	SESSION_DOSSIER_SAUVER.ahk
;	=========================================================== %






the way for restore > the folders and size&position:(from the files.ses )
;	=========================================================== %		SESSION_DOSSIER_SAUVER.ahk
;	=========================================================== % le fichier doivent porter l'extension ;ses
;	=========================================================== %
; #NAME>	SESSION_DOSSIER_RESTAURATION.ahk					; cause can run standAlone
;	=========================================================== %
; (if not open > open it else moveit )
; A way for RESTORE size/position each Open Folders from textFile.ses


; cause can run standAlone
if %0% != 0		
	{					;	argument
	data_file= %1%
	Gosub ARGUMENT
		}
		Else
	Gosub SESSION_DOSSIER_CHOISIR
Return
;	=========================================================== %



;	=========================================================== %
		
		ARGUMENT:
		
	SoundBeep, 6050, 10	;	son de démarage
	; data_file= %1%
	SplitPath, data_file, name, dir, ext, name_no_ext, drive	; To fetch all info:
	if ext<>ses
			{	SoundBeep, 1050, 50	;	son de démarage
				MsgBox , 4160 , , !Extension demandée *.ses `n"%data_file%"
				; Gosub CONSOLE
			
			}
		Else
			{				
				Gosub SESSION_DOSSIER_RESTAURATION
				SoundBeep, 8050, 10	;	son de démarage
				ExitApp
			}
	Return
;	=========================================================== %



;	=========================================================== %
	SESSION_DOSSIER_OUVRIR:
	data_file= %1%
	Gosub SESSION_DOSSIER_RESTAURATION
	Return
;	=========================================================== %
	
;	=========================================================== %
	SESSION_DOSSIER_CHOISIR:	
	
	Gui , +LastFoundExist
	Gui +OwnDialogs  ; Force the user to dismiss the FileSelectFile dialog before returning to the main window.

	FileSelectFile, OutputVar, 32, %data_file%, OUVRIR un fichier de session, *.ses
		if OutputVar=
		{
		IfInString , A_ScriptName, SESSION_DOSSIER_RESTAURATION	; script sans console
		ExitApp												; donc refermer
		Else
		Return
		}
		
	data_file=%OutputVar%
	
	TrayTip , RESTAURATION session de DOSSIERS, RESTAURATION en cours
	Gosub SESSION_DOSSIER_RESTAURATION
	TrayTip , RESTAURATION session de DOSSIERS, %info%
	
	Return
;	=========================================================== %
		
;	=========================================================== %
	
	SESSION_DOSSIER_RESTAURATION:
SetTitleMatchMode 3
	info=
	lst_ouv=
; 	===============
	WinGet, IDs, List, , , Program Manager
		
	Loop, %IDs%
		{
		StringTrimRight, id, IDs%a_index%, 0
		WinGetTitle, title, ahk_id %id%
		lst_ouv= %lst_ouv%%title%`n
		}
		; MsgBox , 4160 , , %lst_ouv% 
		; info="%data_file%"`n`n
; 	===============
	
; 	===============
	Loop
		{ 	ouvert=
			FileReadLine , line, %data_file%, %A_Index% 
			if ErrorLevel
			   break
			   
			LineArray=
			StringSplit, LineArray , line , |
			name= %LineArray1%
	IfExist %LineArray1%
			{
		loop, parse, lst_ouv, `n
			if name= %A_LoopField%
				{
	TrayTip , RESTAURATION session de DOSSIERS, OK EXISTE > move
				WinActivate , %A_LoopField%
				WinMove , %A_LoopField%,, %LineArray2% ,%LineArray3% ,%LineArray4% ,%LineArray5% 
				ToolTip  , BOUGE >  %name%  %LineArray2%  %LineArray3%  %LineArray4%  %LineArray5% 
				ouvert=1
				; info=%info%OK Existe> %LineArray1%`n
				break
				}
				
			if ouvert=
				{
	TrayTip , RESTAURATION session de DOSSIERS, OUVERTURE!
				ToolTip  , OUVERTURE >  %LineArray1%  %LineArray2%  %LineArray3%  %LineArray4%  %LineArray5% 
				Run, Explorer /n`,%LineArray1% ,, UseErrorLevel
				Sleep 250
				WinActivate , %LineArray1%
				WinMove, %LineArray1%,, %LineArray2% ,%LineArray3% ,%LineArray4% ,%LineArray5% 
				ToolTip  , BOUGE >  %LineArray1%  %LineArray2%  %LineArray3%  %LineArray4%  %LineArray5% 
				ouvert=1
		;  VERIFIER si deja ouvert et si oui faire le move
				}
				
			}	
		Else
			info=%info%NoGood:`n%LineArray1%`n
			;	MsgBox , 4160 , , =%ouvert% 
			
	TrayTip , RESTAURATION session de DOSSIERS, %info%
			
		}
; 	===============

ToolTip	
Return
;	=========================================================== %
; #END of > NAME>	SESSION_DOSSIER_RESTAURATION.ahk
;	=========================================================== %






And a little nice gui (for this two scripts):
;
; AutoHotkey Version: 1.x
; Language:       English
; Platform:       Win9x/NT
; Author:         soggos at free.fr
; version:        1.0
;
; Application-Name:	DOSSIERs_SESSION.ahk
;
; Script Function:
;	-Save size and position of Actual open Folder in a file like xxxx.ses (extension is ses)
;	-Restore list (from xxxx.ses) Folder (size & position) (IfExist)
; 
;	=========================================================== %

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#UseHook						;  Forces the use of the hook to implement all or some keyboard hotkeys.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
SetTitleMatchMode 3
; 1: A window's title must start with the specified WinTitle to be a match.
; 2: A window's title can contain WinTitle anywhere inside it to be a match. 
; 3: A window's title must exactly match WinTitle to be a match.
#SingleInstance force 	;force		   	;  une seule instance
;	=========================================================== %

	data_file = %A_ScriptDir%\win_save.ses


if %0% != 0		
	{					;	argument
	data_file= %1%
	Gosub ARGUMENT
		}
	Else
	Gosub CONSOLE

Return
;	=========================================================== %




;	=========================================================== %
#include SESSION_DOSSIER_SAUVER.ahk
#include SESSION_DOSSIER_RESTAURATION.ahk
;	=========================================================== %




;	========================================================== %

	CONSOLE:
	
	Gui, +LastFound
	Gui , -Resize +SysMenu +Caption +AlwaysOnTop
	
	Gui , Add, GroupBox,  x15 y5 w280 h55  	, session Dossiers
	
	Gui , Add, Button,  x30 y30 w120 h20  	gSESSION_DOSSIER_SAUVER			, SAUVEZ la session
	Gui , Add, Button,  x150 y30 w120 h20  	gSESSION_DOSSIER_CHOISIR		, OUVRIR une session

	GUI , Show,  x620 Y50  , DOSSIERs_sessions




Return
;	=========================================================== %


;	=========================================================== %
	guiclose:
	guiescape:
	; Reload
	ExitApp
;	=========================================================== %



;	=========================================================== %
	GuiDropFiles: 
	
	SoundBeep, 6050, 10	;	son de démarage
Loop, parse, A_GuiEvent, `n
	{
	data_file= %A_LoopField%
	Break
	}
	; Gosub ARGUMENT
	
	SplitPath, data_file, name, dir, ext, name_no_ext, drive	; To fetch all info:
	if ext<>ses
			{	SoundBeep, 1050, 50	;	son de démarage
				MsgBox , 4160 , , Mauvaise extension (*.ses) "%data_file%"
			;	Gosub CONSOLE
			
			}
		Else
			{				
				Gosub SESSION_DOSSIER_RESTAURATION
				SoundBeep, 8050, 10	;	son de démarage
			;	ExitApp
			}

Return
;	=========================================================== %










And this 3 scripts in this > DOSSIERs_SESSION.ahk
;
; AutoHotkey Version: 1.x
; Language:       English
; Platform:       Win9x/NT
; Author:         soggos at free.fr
; version:        1.0
;
; Application-Name:	DOSSIERs_SESSION.ahk
;
; Script Function:
;	-Save size and position of Actual open Folder in a file like xxxx.ses (extension is ses)
;	-Restore list (from xxxx.ses) Folder (size & position) (IfExist)
; 
;	=========================================================== %


;	=========================================================== %
; #BEGIN of > COMPILED-VERSION >		DOSSIERs_SESSION.ahk
;	=========================================================== %
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#UseHook						;  Forces the use of the hook to implement all or some keyboard hotkeys.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
SetTitleMatchMode 3
; 1: A window's title must start with the specified WinTitle to be a match.
; 2: A window's title can contain WinTitle anywhere inside it to be a match. 
; 3: A window's title must exactly match WinTitle to be a match.
#SingleInstance force 	;force		   	;  une seule instance
;	=========================================================== %

	data_file = %A_ScriptDir%\win_save.ses


if %0% != 0		
	{					;	argument
	data_file= %1%
	Gosub ARGUMENT
		}
	Else
	Gosub CONSOLE

Return
;	=========================================================== %




;	=========================================================== %
; #include SESSION_DOSSIER_SAUVER.ahk
; #include SESSION_DOSSIER_RESTAURATION.ahk
;	=========================================================== %




;	========================================================== %

	CONSOLE:
	
	Gui, +LastFound
	Gui , -Resize +SysMenu +Caption +AlwaysOnTop
	
	Gui , Add, GroupBox,  x15 y5 w280 h55  	, session Dossiers
	
	Gui , Add, Button,  x30 y30 w120 h20  	gSESSION_DOSSIER_SAUVER		, SAUVEZ la session
	Gui , Add, Button,  x150 y30 w120 h20  	gSESSION_DOSSIER_CHOISIR		, OUVRIR une session

	GUI , Show,  x620 Y50  , DOSSIERs_sessions




Return
;	=========================================================== %


;	=========================================================== %
	guiclose:
	guiescape:
	; Reload
	ExitApp
;	=========================================================== %



;	=========================================================== %
	GuiDropFiles: 
	
	SoundBeep, 6050, 10	;	son de démarage
Loop, parse, A_GuiEvent, `n
	{
	data_file= %A_LoopField%
	Break
	}
	; Gosub ARGUMENT
	
	SplitPath, data_file, name, dir, ext, name_no_ext, drive	; To fetch all info:
	if ext<>ses
			{	SoundBeep, 1050, 50	;	son de démarage
				MsgBox , 4160 , , Mauvaise extension (*.ses) "%data_file%"
			;	Gosub CONSOLE
			
			}
		Else
			{				
				Gosub SESSION_DOSSIER_RESTAURATION
				SoundBeep, 8050, 10	;	son de démarage
			;	ExitApp
			}

Return
;	=========================================================== %










;	=========================================================== %		SESSION_DOSSIER_SAUVER.ahk
;	=========================================================== % le fichier doivent porter l'extension ;ses
;	=========================================================== %
; #NAME>	SESSION_DOSSIER_SAUVER.ahk							; cause can run standAlone
;	=========================================================== %

	SESSION_DOSSIER_SAUVER:
	if data_file=
		data_file = %A_ScriptDir%\win_save.ses
		
	; Gui +LastFoundExist
	Gui +OwnDialogs  			; Force the user to dismiss the FileSelectFile dialog before returning to the main window.
	FileSelectFile, OutputVar, 16, %data_file%, SAUVER la SESSION de DOSSIER dans un fichier de session, *.ses
	if OutputVar=
		{
		IfInString , A_ScriptName, SESSION_DOSSIER_SAUVER	; script sans console
		ExitApp												; donc refermer
		Else
		Return
		}
	TrayTip , SAUVEGARDE session Dossier, en cours
	SplitPath , OutputVar, name, dir, ext, name_no_ext, drive	; To fetch all info:
	if ext<>ses
			data_file=%OutputVar%.ses
			Else
			data_file=%OutputVar%
	If FileExist(data_file)
	   FileDelete, %data_file%

WinGet, IDs, List, , , Program Manager
Loop, %IDs%
	{
	StringTrimRight, id, IDs%a_index%, 0
	WinGetTitle, title, ahk_id %id%

	; only existan folder
	IfNotExist %title%
		continue	
	FileGetAttrib , attrib , %title%
	IfNotInString , attrib ,D
		Continue
	
	WinGet, IsMinMax, MinMax, ahk_id %id%
	If IsMinMax <> 0
	WinRestore, ahk_id %id%
		
	WinGetPos, x, y, w, h, ahk_id %id%

	fields= %title%|%x%|%y%|%w%|%h%`n
	FileAppend, %fields%, %data_file%

	
	; remettre
	   If (IsMinMax < 0)
	   {
		  WinMinimize, ahk_id %id%
	   }
	   Else If (IsMinMax > 0)
	   {
		  WinMaximize, ahk_id %id%
	   }
	   
	}
	TrayTip
	
		IfInString , A_ScriptName, SESSION_DOSSIER_SAUVER	; script sans console
		ExitApp												; donc refermer
Return
; ===============
;	=========================================================== %
; #END of > NAME>	SESSION_DOSSIER_SAUVER.ahk
;	=========================================================== %




;	=========================================================== %		SESSION_DOSSIER_SAUVER.ahk
;	=========================================================== % le fichier doivent porter l'extension ;ses
;	=========================================================== %
; #NAME>	SESSION_DOSSIER_RESTAURATION.ahk					; cause can run standAlone
;	=========================================================== %


; cause can run standAlone
if %0% != 0		
	{					;	argument
	data_file= %1%
	Gosub ARGUMENT
		}
		Else
	Gosub SESSION_DOSSIER_CHOISIR
Return
;	=========================================================== %



;	=========================================================== %
		
		ARGUMENT:
		
	SoundBeep, 6050, 10	;	son de démarage
	; data_file= %1%
	SplitPath, data_file, name, dir, ext, name_no_ext, drive	; To fetch all info:
	if ext<>ses
			{	SoundBeep, 1050, 50	;	son de démarage
				MsgBox , 4160 , , !Extension demandée *.ses `n"%data_file%"
				; Gosub CONSOLE
			
			}
		Else
			{				
				Gosub SESSION_DOSSIER_RESTAURATION
				SoundBeep, 8050, 10	;	son de démarage
				ExitApp
			}
	Return
;	=========================================================== %



;	=========================================================== %
	SESSION_DOSSIER_OUVRIR:
	data_file= %1%
	Gosub SESSION_DOSSIER_RESTAURATION
	Return
;	=========================================================== %
	
;	=========================================================== %
	SESSION_DOSSIER_CHOISIR:	
	
	Gui , +LastFoundExist
	Gui +OwnDialogs  ; Force the user to dismiss the FileSelectFile dialog before returning to the main window.

	FileSelectFile, OutputVar, 32, %data_file%, OUVRIR un fichier de session, *.ses
		if OutputVar=
		{
		IfInString , A_ScriptName, SESSION_DOSSIER_RESTAURATION	; script sans console
		ExitApp												; donc refermer
		Else
		Return
		}
		
	data_file=%OutputVar%
	
	TrayTip , RESTAURATION session de DOSSIERS, RESTAURATION en cours
	Gosub SESSION_DOSSIER_RESTAURATION
	TrayTip , RESTAURATION session de DOSSIERS, %info%
	
	Return
;	=========================================================== %
		
;	=========================================================== %
	
	SESSION_DOSSIER_RESTAURATION:
SetTitleMatchMode 3
	info=
	lst_ouv=
; 	===============
	WinGet, IDs, List, , , Program Manager
		
	Loop, %IDs%
		{
		StringTrimRight, id, IDs%a_index%, 0
		WinGetTitle, title, ahk_id %id%
		lst_ouv= %lst_ouv%%title%`n
		}
		; MsgBox , 4160 , , %lst_ouv% 
		; info="%data_file%"`n`n
; 	===============
	
; 	===============
	Loop
		{ ouvert=
			FileReadLine , line, %data_file%, %A_Index% 
			if ErrorLevel
			   break
			   
			LineArray=
			StringSplit, LineArray , line , |
			name= %LineArray1%
	IfExist %LineArray1%
			{
		loop, parse, lst_ouv, `n
			if name= %A_LoopField%
				{
	TrayTip , RESTAURATION session de DOSSIERS, OK EXISTE > move
				WinActivate , %A_LoopField%
				WinMove, %A_LoopField%,, %LineArray2% ,%LineArray3% ,%LineArray4% ,%LineArray5% 
				ToolTip  , BOUGE >  %name%  %LineArray2%  %LineArray3%  %LineArray4%  %LineArray5% 
				ouvert=1
				; info=%info%OK Existe> %LineArray1%`n
				break
				}
				
			if ouvert=
				{
	TrayTip , RESTAURATION session de DOSSIERS, OUVERTURE!
				ToolTip  , OUVERTURE >  %LineArray1%  %LineArray2%  %LineArray3%  %LineArray4%  %LineArray5% 
				Run, Explorer /n`,%LineArray1% ,, UseErrorLevel
				Sleep 250
				WinActivate , %LineArray1%
				WinMove, %LineArray1%,, %LineArray2% ,%LineArray3% ,%LineArray4% ,%LineArray5% 
				ToolTip  , BOUGE >  %LineArray1%  %LineArray2%  %LineArray3%  %LineArray4%  %LineArray5% 
				ouvert=1
		;  VERIFIER si deja ouvert et si oui faire le move
				}
				
			}	
		Else
			info=%info%NoGood:`n%LineArray1%`n
			;	MsgBox , 4160 , , =%ouvert% 
			
	TrayTip , RESTAURATION session de DOSSIERS, %info%
			
		}
; 	===============

ToolTip	
Return
;	=========================================================== %
; #END of > NAME>	SESSION_DOSSIER_RESTAURATION.ahk
;	=========================================================== %

;	=========================================================== %
; #END of > COMPILED-VERSION >		DOSSIERs_SESSION.ahk
;	=========================================================== %





..... AHK is so great....