; @AZJIO 22.03.2010
#NoTrayIcon
Global $aVisibleWindows[1] = ["0"], $sTmp, $sTitle
GUICreate("SaveFolders", 500, 200)
GUICtrlCreateLabel("Session", 15, 15, 41, 18)
$Session = GUICtrlCreateCombo("current", 15, 32, 470, 25, 0x3) ; $CBS_DROPDOWNLIST=0x3
GUICtrlCreateLabel("folders", 15, 71, 74, 18)
$Folderlist = GUICtrlCreateCombo("", 15, 88, 470, 25, 0x3)
$Open = GUICtrlCreateButton("Open", 390, 12, 73, 20)
GUICtrlSetTip(-1, "Open session")
$Save = GUICtrlCreateButton("Save", 390, 68, 73, 20)
GUICtrlSetTip(-1, "Save session")
$Openfolder = GUICtrlCreateButton("Open all folders", 80, 130, 130, 33)
$close = GUICtrlCreateButton("Close all folders", 290, 130, 130, 33)
_GetWindows()
_search()
GUISetState ()
While 1
$msg = GUIGetMsg()
Select
Case $msg = $Save
$file_save = FileSaveDialog( "Save session", @ScriptDir & "", "Session (*.inc)", 24, "Session.inc")
If @error Then ContinueLoop
$file = FileOpen($file_save, 2)
If $file = -1 Then
MsgBox(0, "Error", "Unable to open file.")
ContinueLoop
EndIf
FileWrite($file, $sTmp)
FileClose($file)
Case $msg = $Open
$file_open = FileOpenDialog("Open session", @ScriptDir & "", "Session (*.inc)", 1 + 4 , "Session.inc")
If @error Then ContinueLoop
$file = FileOpen($file_open, 0)
If $file = -1 Then
MsgBox(0, "Error", "Unable to open file.")
ContinueLoop
EndIf
$sTmp = FileRead($file)
GUICtrlSetData($Session, $file_open)
GUICtrlSetData($Folderlist, $sTmp)
FileClose($file)
Case $msg = $Openfolder
$aPath = StringSplit($sTmp, "|")
For $i=1 To $aPath [0]
If FileExists($aPath[$i]) Then Run('Explorer.exe '&$aPath[$i])
Next
_GetWindows()
Sleep(300)
WinActivate ( "SaveFolders")
Case $msg = $close
$aTitle = StringSplit($sTitle, "|")
For $i=1 To $aTitle [0]
If WinExists ($aTitle[$i]) And $aTitle[$i] <> "Program Manager" Then WinClose ($aTitle[$i])
Next
_GetWindows()
Case $msg = $Session
$file_open=GUICtrlRead ($Session)
If $file_open ='current' Then
_GetWindows()
Else
$file = FileOpen($file_open, 0)
If $file = -1 Then
MsgBox(0, "Error", "Unable to open file.")
ContinueLoop
EndIf
$sTmp = FileRead($file)
FileClose($file)
GUICtrlSetData($Session, $file_open)
If $sTmp <> '' Then
GUICtrlSendMsg($Folderlist, 0x14B, 0, 0)
GUICtrlSetData($Folderlist, $sTmp)
EndIf
EndIf
Case $msg = $Folderlist
$myFolder = GUICtrlRead($Folderlist)
If FileExists($myFolder) Then
Run('Explorer.exe '&$myFolder)
EndIf
;EndIf
Case $msg = -3
Exit
EndSelect
WEnd
Func _GetWindows()
GUICtrlSendMsg($Folderlist, 0x14B, 0, 0)
$AllWindows = WinList()
$sTmp = ""
For $i = 1 To $AllWindows[0][0]
If _IsVisible($AllWindows[$i][1]) Then
$iPID = WinGetProcess($AllWindows[$i][0])
$sProcessPath = _ProcessPath($iPID)
If $AllWindows[$i][0] <> "" And $AllWindows[$i][0] <> "Program Manager" And StringRight($sProcessPath, 12)='explorer.exe' Then
$iIndex = $aVisibleWindows[0] + 1
ReDim $aVisibleWindows[$iIndex + 1]
$aVisibleWindows[0] = $iIndex
$aVisibleWindows[$iIndex] = $AllWindows[$i][0]
If $sTmp = "" Then
$sTmp &= ControlGetText ( $aVisibleWindows[$iIndex], '', "[CLASS:Edit; INSTANCE:1]")
$sTitle &= $aVisibleWindows[$iIndex]
Else
$sTmp &= "|" & ControlGetText ( $aVisibleWindows[$iIndex], '', "[CLASS:Edit; INSTANCE:1]")
$sTitle &= "|" & $aVisibleWindows[$iIndex]
EndIf
EndIf
EndIf
Next
If $sTmp <> "" Then
GUICtrlSetData($Folderlist, $sTmp)
Else
GUICtrlSetData($Folderlist, "<No Data>")
EndIf
EndFunc
Func _IsVisible($handle)
If BitAND(WinGetState($handle), 4) Then
If BitAND(WinGetState($handle), 2) Then
Return 1
Else
Return 0
EndIf
EndIf
EndFunc
Func _search()
$sestmp=''
$search = FileFindFirstFile(@ScriptDir & "\*.inc")
If $search <> -1 Then
While 1
$file = FileFindNextFile($search)
If @error Then ExitLoop
$sestmp&=@ScriptDir & "\"&$file&'|'
WEnd
EndIf
FileClose($search)
GUICtrlSetData($Session, $sestmp)
EndFunc
Func _ProcessPath($iCheckPID)
$strComputer = "."
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Process", "WQL", 0x30)
If IsObj($colItems) Then
For $objItem In $colItems
$sProcessPID = $objItem.ProcessId
If $sProcessPID = $iCheckPID Then
$sProcessPath = $objItem.ExecutablePath
ExitLoop
EndIf
Next
EndIf
If $sProcessPath <> "" Then Return $sProcessPath
EndFunc