Jump to content

Tray on event with variables items ....


FireFox
 Share

Recommended Posts

hi,

Let me explain what I want to do :

There is for example function that refresh process list on tray

So I create trayitems for all process and create menu on them with close it or get full path (I repeat that's an example)

How can I make on event trayitem for close process and read item wich is written name of processus for close it ?

(can't name or use variables for trayitems because it's variable ....

Thanks for anyhelp if anyone have understand :)

Link to comment
Share on other sites

hi,

Let me explain what I want to do :

There is for example function that refresh process list on tray

So I create trayitems for all process and create menu on them with close it or get full path (I repeat that's an example)

How can I make on event trayitem for close process and read item wich is written name of processus for close it ?

(can't name or use variables for trayitems because it's variable ....

Thanks for anyhelp if anyone have understand :)

I did not understand your question.

There is a native French forum for AutoIt: www.autoitscript.fr/forum/

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

I did not understand your question.

There is a native French forum for AutoIt: www.autoitscript.fr/forum/

:)

No thanks :) I prefer the "official" autoit...

I explain my question because when I wrote it i was on my ipod so it wasn't easy....

In my script I have Tray wich have random trayitems, and on this random items I have created menu and created on other items

So I want to make on event this random items and read associated item of menu....

this could help you to understand :

Posted Image

Link to comment
Share on other sites

No thanks :) I prefer the "official" autoit...

I explain my question because when I wrote it i was on my ipod so it wasn't easy....

In my script I have Tray wich have random trayitems, and on this random items I have created menu and created on other items

So I want to make on event this random items and read associated item of menu....

this could help you to understand :

Posted Image

I still don't fully understand, but I'm not the crunchiest baguette in the basket... :)

This will go much better with actual code to talk about, but you seem to just be concerned with recognizing events from multiple tray items without knowing in advance how many there will be, so you haven't assigned them specific variable names.

The easy answer is to keep them in an array, then an array search for the control ID or handle (from @TRAY_ID or @GUI_CTRLID in the event function) will find the item you want. If you keep them in a 2D array, you can have the identity of the control in [n][0] and the text or some other indication of what you want done with that particular item in [n][1].

A working demo:

#include <GuiConstantsEx.au3>
#include <Process.au3>
#include <Array.au3>

Opt("GuiOnEventMode", 1)
Opt("TrayOnEventMode", 1)
Opt("TrayMenuMode", 1)

Global $hGUI, $Button1

; [0][0] = count, [0][1] = TrayMenu ID
; [n][0] = TrayMenuItem ID, [n][1] = PID
Global $avTrayItems[1][2] = [[0, 0]]

$hGUI = GUICreate("Test", 300, 200)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit")
$Button1 = GUICtrlCreateButton("UPDATE", 100, 150, 100, 30)
GUICtrlSetOnEvent(-1, "_UpdateTray")
GUISetState()

While 1
    Sleep(20)
WEnd


Func _Quit()
    Exit
EndFunc  ;==>_Quit


Func _UpdateTray()
; Delete existing list
    If $avTrayItems[0][1] Then
        ConsoleWrite("Debug: Deleting old menu..." & @LF)
        For $n = 1 To $avTrayItems[0][0]
            TrayItemDelete($avTrayItems[$n][0])
        Next
        TrayItemDelete($avTrayItems[0][1])
        Global $avTrayItems[1][2] = [[0, 0]]
    EndIf
    
; Create new list
    Local $avProc = ProcessList()
    ReDim $avTrayItems[UBound($avProc)][2]
    $avTrayItems[0][1] = TrayCreateMenu("Processes")
    For $n = 1 To $avProc[0][0]
        $avTrayItems[$n][0] = TrayCreateItem($avProc[$n][0], $avTrayItems[0][1])
        TrayItemSetOnEvent(-1, "_TrayItemHit")
        $avTrayItems[$n][1] = $avProc[$n][1]
    Next
EndFunc  ;==>_UpdateTray


Func _TrayItemHit()
    Local $i = _ArraySearch($avTrayItems, @TRAY_ID, 1)
    If Not ProcessExists($avTrayItems[$i][1]) Then
        MsgBox(16, "Error", "Process PID " & $avTrayItems[$i][1] & " no longer exists.")
        Return
    EndIf
    Local $sName = _ProcessGetName($avTrayItems[$i][1])
    Local $avMemStats = ProcessGetStats($avTrayItems[$i][1], 0)
    If IsArray($avMemStats) Then
        $avMemStats[0] = "WorkingSetSize = " & $avMemStats[0]
        $avMemStats[1] = "PeakWorkingSetSize = " & $avMemStats[1]
        _ArrayDisplay($avMemStats, $sName & " Mem Stats")
    Else
        MsgBox(16, "Error", "Cannot retrieve Mem Stats for PID " & $avTrayItems[$i][1] & " (" & $sName & ")")
    EndIf
EndFunc  ;==>_TrayItemHit

o:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

@PSaltyDS

I've got this error :

==> Array variable subscript badly formatted.:
MsgBox(64, "EDIT", $avTrayItem1[$i][1])
MsgBox(64, "EDIT", $avTrayItem1[^ ERROR

Here is part of my code :

Opt("TrayOnEventMode", 1)
Opt("TrayMenuMode", 1)
#include <Array.au3>
Global $avTrayItem1[1][2] = [[0, 0]]
Global $avTrayItem2[1][2] = [[0, 0]]
Global $avTrayItem3[1][2] = [[0, 0]]

$ListM = TrayCreateMenu("List")
TrayCreateItem("Clean List", $ListM)
TrayItemSetOnEvent(-1, "_Clean")
TrayCreateItem("Refresh List", $ListM)
TrayItemSetOnEvent(-1, "_RefreshTempFolder")
$ViewM = TrayCreateMenu("View List", $ListM)
TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, "_Exit")
_RefreshTempFolder()
TraySetToolTip("Scriptner <d3montools>")

If FileFindFirstFile(@TempDir & "\Scriptner\*.au3") = -1 Then
    DirCreate(@TempDir & "\Scriptner")
    Global $NB = 0
Else
    $FIRST = FileFindFirstFile(@TempDir & "\Scriptner\*.au3")
    $TEMPNB = 0
    While 1
        $NEXT = FileFindNextFile($FIRST)
        If @error Then ExitLoop
        $TEMPNB = $TEMPNB + 1
    WEnd
    Global $NB = $TEMPNB
    FileClose($FIRST)
EndIf

Func _Exit()
    Exit
EndFunc  ;==>_Exit

Func _Clean()
    TrayTip("Scriptner <d3montools>", "Cleaning temp folder...", 3, 4)
    FileDelete(@TempDir & "\Scriptner\*.au3")
    If $avTrayItem1[0][1] Then
        For $n = 1 To $avTrayItem1[0][0]
            TrayItemDelete($avTrayItem1[$n][0])
        Next
        TrayItemDelete($avTrayItem1[0][1])
        Global $avTrayItem1[1][2] = [[0, 0]]
    EndIf
    $ViewM = TrayCreateMenu("View List", $ListM)
    TrayCreateItem("temp folder...", $ViewM)
    TrayItemSetOnEvent(-1, "_TempFolder")
    TrayCreateItem("Nothing", $ViewM)
    TrayTip("Scriptner <d3montools>", "Temp folder cleaned !", 3, 4)
    _ReduceMemory(@ScriptName)
EndFunc  ;==>_Clean

Func _RefreshTempFolder()
    ReDim $avTrayItem1[9999][2]
    ReDim $avTrayItem2[9999][2]
    ReDim $avTrayItem3[9999][2]
    TrayItemDelete($ViewM)

    $FIRST = FileFindFirstFile(@TempDir & "\Scriptner\*.au3")
    $ViewM = TrayCreateMenu("View List", $ListM)
    While 1
        $number = 1
        $NEXT = FileFindNextFile($FIRST)
        If ($NEXT <> "") Then
            $avTrayItem1[0][1] = TrayCreateMenu($NEXT, $ViewM)
            $avTrayItem2[$number][0] = TrayCreateItem("Edit", $avTrayItem1[0][1])
            TrayItemSetOnEvent(-1, "_EditScript")
            $avTrayItem3[$number][0] = TrayCreateItem("Run", $avTrayItem1[0][1])
            TrayItemSetOnEvent(-1, "_RunScript")
            $avTrayItem1[$number][1] = $NEXT
            $number = $number + 1
        Else
            ExitLoop
        EndIf
        If @error Then ExitLoop
    WEnd
    FileClose($FIRST)
    TrayCreateItem("temp folder...", $ViewM)
    TrayItemSetOnEvent(-1, "_TempFolder")
    _ReduceMemory(@ScriptName)
EndFunc  ;==>_RefreshTempFolder

#Region temp -------------------------------------------------------------
Func _TempFolder()
    ShellExecute("explorer.exe", @TempDir & "\Scriptner")
    _ReduceMemory(@ScriptName)
EndFunc  ;==>_TempFolder

Func _RunScript()
    Local $i = _ArraySearch($avTrayItem1, @TRAY_ID, 1)
    MsgBox(64, "RUN", $avTrayItem1[$i][1])
EndFunc  ;==>_RunScript

Func _EditScript()
    Local $i = _ArraySearch($avTrayItem1, @TRAY_ID, 1)
    MsgBox(64, "EDIT", $avTrayItem1[$i][1])
EndFunc  ;==>_EditScript
#EndRegion temp -------------------------------------------------------------

While 1
    Sleep(250)
WEnd

I hope you will understand my script and help me :) :) o:)

Link to comment
Share on other sites

@PSaltyDS

I've got this error :

==> Array variable subscript badly formatted.:
MsgBox(64, "EDIT", $avTrayItem1[$i][1])
MsgBox(64, "EDIT", $avTrayItem1[^ ERROR

Here is part of my code:

; ...<snip>

Func _EditScript()
    Local $i = _ArraySearch($avTrayItem1, @TRAY_ID, 1)
    MsgBox(64, "EDIT", $avTrayItem1[$i][1])
EndFunc ;==>_EditScript

; ...<snip>

I hope you will understand my script and help me :)o:);)

Add some error handling. You get -1 back from _ArraySearch() if it's not found, which is an invalid array index:
Func _EditScript()
    Local $i = _ArraySearch($avTrayItem1, @TRAY_ID, 1)
    Local $iErrSav = @error
    If @error Then
        MsgBox(16, "Error", "Tray ID " & @TRAY_ID & " search error:  $i = " & $i & "  @error = " & $iErrSav)
        _ArrayDisplay($avTrayItem1, "Debug: $avTrayItem1")
    Else
        MsgBox(64, "EDIT", $avTrayItem1[$i][1])
    EndIf
EndFunc  ;==>_EditScript

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

my media player does this.

in ChooseFunc() it uses a for loop to check the array for which item was clicked. the [0] dimension is the size of the array.

Func ChooseFunc()
    _SoundClose($dir & "\" & $List[$x])
    For $l = 1 to $List[0]
        Select
        Case @GUI_CtrlId = $CreateItem[$l]
        $x = $l
        EndSelect
    Next

    PlaySong()

EndFunc
Edited by Tomb
Link to comment
Share on other sites

@PsaltyDS

Ive tried for 2hours to make my script and Ive done same thing like your example but again ArraySearch error :

CODE

;================================================================================

;# Title .........: Scriptner.au3 #

;# Description ...: Run AutoIt script from Clipboard #

;# Date ..........: 16.12.08 #

;# Version .......: 1.0 #

;# Author ........: FireFox #

;# © 2008 d3mon Corporation #

;================================================================================

Opt("TrayOnEventMode", 1)

Opt("TrayMenuMode", 1)

#include <Array.au3>

_ReduceMemory(@ScriptName)

Global $avTrayItems[1][2] = [[0, 0]]

Global $tempnb = 1

$ListM = TrayCreateMenu("List")

TrayCreateItem("Clean List", $ListM)

TrayItemSetOnEvent(-1, "_Clean")

TrayCreateItem("Refresh List", $ListM)

TrayItemSetOnEvent(-1, "_RefreshTempFolder")

$avTrayItems[0][1] = TrayCreateMenu("View List", $ListM)

TrayCreateItem("Exit")

TrayItemSetOnEvent(-1, "_Exit")

_Refreshtempfolder()

TraySetToolTip("Scriptner <d3montools>")

If FileFindFirstFile(@TempDir & "\Scriptner\*.au3") = -1 Then

DirCreate(@TempDir & "\Scriptner")

Global $NB = 0

Else

_nbtemp()

Global $NB = $tempnb

EndIf

Func _Exit()

Exit

EndFunc ;==>_Exit

Func _Clean()

TrayTip("Scriptner <d3montools>", "Cleaning temp folder...", 3, 4)

FileDelete(@TempDir & "\Scriptner\*.au3")

_DeleteTray()

TrayTip("Scriptner <d3montools>", "Temp folder cleaned !", 3, 4)

_ReduceMemory(@ScriptName)

EndFunc ;==>_Clean

Func _DeleteTray()

For $n = 1 To $avTrayItems[0][0]

TrayItemDelete($avTrayItems[$n][0])

Next

TrayItemDelete($avTrayItems[0][1])

Global $avTrayItems[1][2] = [[0, 0]]

EndFunc ;==>_DeleteTray

Func _Refreshtempfolder()

_nbtemp()

_DeleteTray()

ReDim $avTrayItems[12][2]

$FIRST = FileFindFirstFile(@TempDir & "\Scriptner\*.au3")

$avTrayItems[0][1] = TrayCreateMenu("View List", $ListM)

While 1

$n = 1

$NEXT = FileFindNextFile($FIRST)

If @error Then ExitLoop

If ($NEXT <> "") Then

$avTrayItems[$n][0] = TrayCreateItem($NEXT, $avTrayItems[0][1])

TrayItemSetOnEvent(-1, "_EditScript")

;~ $avTrayItems[$n][0] = TrayCreateMenu($NEXT, $avTrayItems[0][1])

;~ TrayCreateItem("Edit", $avTrayItems[$n][0])

;~ TrayItemSetOnEvent(-1, "_EditScript")

;~ TrayCreateItem("Run", $avTrayItems[$n][0])

;~ TrayItemSetOnEvent(-1, "_RunScript")

$avTrayItems[$n][1] = $NEXT

$n = $n + 1

Else

ExitLoop

EndIf

WEnd

FileClose($FIRST)

TrayCreateItem("temp folder...", $avTrayItems[0][1])

TrayItemSetOnEvent(-1, "_TempFolder")

_ReduceMemory(@ScriptName)

EndFunc ;==>_Refreshtempfolder

#Region temp -------------------------------------------------------------

Func _TempFolder()

ShellExecute("explorer.exe", @TempDir & "\Scriptner")

_ReduceMemory(@ScriptName)

EndFunc ;==>_TempFolder

Func _RunScript()

Local $i = _ArraySearch($avTrayItems, @TRAY_ID, 1)

Local $iErrSav = @error

If @error Then

MsgBox(16, "Error", "Tray ID " & @TRAY_ID & " search error: $i = " & $i & " @error = " & $iErrSav)

_ArrayDisplay($avTrayItems, "Debug: $avTrayItem1")

Else

MsgBox(64, "Run", $avTrayItems[$i][1])

EndIf

EndFunc ;==>_RunScript

Func _EditScript()

Local $i = _ArraySearch($avTrayItems, @TRAY_ID, 1)

Local $iErrSav = @error

If @error Then

MsgBox(16, "Error", "Tray ID " & @TRAY_ID & " search error: $i = " & $i & " @error = " & $iErrSav)

_ArrayDisplay($avTrayItems, "Debug: $avTrayItem1")

Else

MsgBox(64, "EDIT", $avTrayItems[$i][1])

EndIf

EndFunc ;==>_EditScript

Func _nbtemp()

$FIRST = FileFindFirstFile(@TempDir & "\Scriptner\*.au3")

$tempnb = 0

While 1

$NEXT = FileFindNextFile($FIRST)

If @error Then ExitLoop

$tempnb = $tempnb + 1

WEnd

Global $tempnb = $tempnb

FileClose($FIRST)

EndFunc ;==>_nbtemp

#EndRegion temp -------------------------------------------------------------

While 1

Sleep(250)

WEnd

;===============================================================================

; Function Name: _ReduceMemory

; Author(s): jftuga

Func _ReduceMemory($i_PID = -1)

If $i_PID <> -1 Then

Local $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1F0FFF, 'int', False, 'int', $i_PID)

Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $ai_Handle[0])

DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $ai_Handle[0])

Else

Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', -1)

EndIf

Return $ai_Return[0]

EndFunc ;==>_ReduceMemory

;===============================================================================

:)

Edited by FireFox
Link to comment
Share on other sites

  • 1 year later...

Thanks

;  @AZJIO 27.03.2010
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_OutFile=SaveFolders.exe
#AutoIt3Wrapper_icon=SaveFolders.ico
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_UseAnsi=y
#AutoIt3Wrapper_Res_Comment=-
#AutoIt3Wrapper_Res_Description=SaveFolders.exe
#AutoIt3Wrapper_Res_Fileversion=0.5.0.0
#AutoIt3Wrapper_Res_LegalCopyright=AZJIO
#AutoIt3Wrapper_Res_Language=1049
#AutoIt3Wrapper_Run_AU3Check=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <Array.au3>

Opt("TrayOnEventMode", 1)
Opt("TrayMenuMode", 1)

Global $sTmp, $d, $file, $file_open0
Global $avTrayItems[1]

$nMain = GUICreate("Edit session", 602, 285, -1, -1, -1, 0x00000010) ;drag-and-drop
GUISetBkColor (0xF9F9F9)
$Label5 = GUICtrlCreateLabel('Filename', 10,3,260,16)
GUICtrlCreateLabel ("drag-and-drop", 480,3,120,16)

$Folderlist = GUICtrlCreateList ("", 10, 24, 580, 230)
GUICtrlSetState(-1, 8)

$nOpen = GUICtrlCreateButton ("Add", 160, 250, 80, 24)
$nDel = GUICtrlCreateButton ("Delete", 250, 250, 90, 24)
$nRestart = GUICtrlCreateButton ("Restart", 350, 250, 80, 24)

$search = FileFindFirstFile(@ScriptDir & "\*.inc")
If $search <> -1 Then
For $d = 1 To 20
    $file_open = FileFindNextFile($search) 
    If @error Then ExitLoop
    _add(25)
Next
EndIf
FileClose($search)

$nEmptily = TrayCreateItem("") 

$curent = TrayCreateMenu("current")

$allfoldercur= TrayCreateItem('Open all', $curent)
TrayItemSetOnEvent(-1, "_allfolder")
_ArrayAdd( $avTrayItems,Eval('allfoldercur'))
_ArrayAdd( $avTrayItems, 'grup0')
$nEmptily = TrayCreateItem("", $curent)

$y=0
$AllWindows = WinList()
For $i = 1 To $AllWindows[0][0]
    If _IsVisible($AllWindows[$i][1]) and $AllWindows[$i][0] <> "" And $AllWindows[$i][0] <> "Program Manager" And StringRight(_ProcessGetPath(WinGetProcess($AllWindows[$i][0])), 12)='explorer.exe' Then
        $y+=1
        Assign('grup0' & $y, TrayCreateItem(ControlGetText ( $AllWindows[$i][0], '', "[CLASS:Edit; INSTANCE:1]"), $curent))
        TrayItemSetOnEvent(-1, "_TrayItemHit")
            _ArrayAdd( $avTrayItems,Eval('grup0' & $y))
            _ArrayAdd( $avTrayItems,ControlGetText ( $AllWindows[$i][0], '', "[CLASS:Edit; INSTANCE:1]"))
            _ArrayAdd( $avTrayItems, 'grup0_' & $y)
    EndIf
Next

$nEmptily = TrayCreateItem("") 

$action = TrayCreateMenu("Actions")

$nUpd= TrayCreateItem("Restart", $action)
TrayItemSetOnEvent(-1, "_restart")

$nSave= TrayCreateItem("Save", $action)
TrayItemSetOnEvent(-1, "_save")

$nClose= TrayCreateItem("Close all", $action)
TrayItemSetOnEvent(-1, "_close")

$nAdd= TrayCreateItem("Add session", $action)
TrayItemSetOnEvent(-1, "_addses")

;ArrayDisplay( $avTrayItems, "Array" )
;HotKeySet('{ESC}', "_Quit")
$nExit = TrayCreateItem("Quit") 
TrayItemSetOnEvent(-1, "_Quit")

TraySetState()

While 1
    Sleep(20)
WEnd

Func _GUI()
    Opt("TrayIconHide", 1)
    $msg = $nMain
    GUISetState()
    _edit()
    $file_open = StringRegExpReplace($file_open0, "(^.*)\\(.*)$", '\2')
    GUICtrlSetData($Label5, $file_open)
    $file = FileOpen($file_open0, 0)
    If $file = -1 Then
       MsgBox(0, "Error", "Unable to open file.")
       return
    EndIf
    $sTmp = FileRead($file)
    FileClose($file)
    $aPath = StringSplit($sTmp, "|")
    GUICtrlDelete($Folderlist)
    $Folderlist = GUICtrlCreateList ("", 10, 24, 580, 230)
    GUICtrlSetState(-1, 8)
    GUICtrlSetData($Folderlist, $sTmp)
While 1
    Sleep(10)
    $msg = GUIGetMsg()
    Select
        ; drag-and-drop
        Case $msg = -13
            If StringInStr(FileGetAttrib(@GUI_DRAGFILE), "D") = 0 Then ContinueLoop
            If StringInStr($sTmp, @GUI_DRAGFILE)>0 Then
                MsgBox(0, "Warning", "DirExists")
                ContinueLoop
            EndIf
            $sTmp &= "|"&@GUI_DRAGFILE
            _updedit()

         ; button "delete"
        Case $msg = $nDel
            $myFolder = GUICtrlRead($Folderlist)
            $myFolder=StringRegExpReplace($myFolder,"[][{}()+.\\^$=#]", "\\$0")
            $sTmp = StringRegExpReplace($sTmp&'|', $myFolder&'\|', '')
            ;$sTmp = StringRegExpReplace($sTmp, '\|\|', '|')
            ;If StringLeft( $sTmp, 1 )='|' Then $sTmp = StringTrimLeft( $sTmp ,1 )
            If StringRight( $sTmp, 1 )='|' Then $sTmp = StringTrimRight( $sTmp ,1 )
            _updedit()

        ;button "Add"
        Case $msg = $nOpen
            $addfold = FileSelectFolder ( "Choose",'')
            If @error Then ContinueLoop
            If StringInStr($sTmp, $addfold)>0 Then
                MsgBox(0, "Warning", "DirExists")
                ContinueLoop
            EndIf
            $sTmp &= "|"&$addfold
            _updedit()
    
        Case $msg = $nRestart
            _restart()
        Case $msg = -3
            Opt("TrayIconHide", 0)
            GUISetState(@SW_HIDE, $nMain)
            ExitLoop
    EndSelect
WEnd
EndFunc

Func _updedit()
            $file = FileOpen($file_open0, 2)
            If $file = -1 Then
                MsgBox(0, "Error", "Unable to open file.")
                return
            EndIf
            FileWrite($file, $sTmp)
            FileClose($file)
            GUICtrlDelete($Folderlist)
            $Folderlist = GUICtrlCreateList ("", 10, 24, 580, 230)
            GUICtrlSetState(-1, 8)
            GUICtrlSetData($Folderlist, $sTmp)
EndFunc  ;==>_addses

; Add session
Func _addses()
    $y=0
    $d+=1
    $file_open = FileOpenDialog("Open", @ScriptDir & "", "Session (*.inc)", 1 + 4 , "Session.inc")
    If @error Then return
    _add(0)
EndFunc  ;==>_addses

; Add item
Func _add($sor)
    $file = FileOpen($file_open, 0)
    If $file = -1 Then
       MsgBox(0, "Error", "Unable to open file.")
       return
    EndIf
    $sTmp = FileRead($file)
    FileClose($file)
    $aPath = StringSplit($sTmp, "|")
    $file_open0=$file_open
    If StringInStr($file_open, "\")>0 Then $file_open = StringRegExpReplace($file_open, "(^.*)\\(.*)$", '\2')
    Assign('Session' & $d, TrayCreateMenu ($file_open,-1,$sor))
    
    
    Assign('edit' & $d, TrayCreateItem('Edit session', Eval('Session' & $d)))
    TrayItemSetOnEvent(-1, "_GUI")
    _ArrayAdd( $avTrayItems,Eval('edit' & $d))
    If StringInStr($file_open0, "\")=0 Then $file_open0 = @ScriptDir & "\" & $file_open0
    _ArrayAdd( $avTrayItems,$file_open0)
    
    Assign('allfolder' & $d, TrayCreateItem('Open all', Eval('Session' & $d)))
    TrayItemSetOnEvent(-1, "_allfolder")
    _ArrayAdd( $avTrayItems,Eval('allfolder' & $d))
    _ArrayAdd( $avTrayItems,'grup' & $d)
    $nEmptily = TrayCreateItem("", Eval('Session' & $d))
    $y=0
    For $i = 1 To $aPath[0]
        If FileExists($aPath[$i]) Then
            $y+=1
            Assign('grup' & $d & '_' & $y, TrayCreateItem($aPath[$i], Eval('Session' & $d)))
            TrayItemSetOnEvent(-1, "_TrayItemHit")
            _ArrayAdd( $avTrayItems,Eval('grup' & $d & '_' & $y))
            _ArrayAdd( $avTrayItems,$aPath[$i])
            _ArrayAdd( $avTrayItems,'grup' & $d & '_' & $y)
        EndIf
    Next
EndFunc  ;==>_add

Func _save()
    $file_save = FileSaveDialog( "Save", @ScriptDir & "", "Session (*.inc)", 24, "Session.inc")
    If @error Then return
    If StringRight($file_save, 4 )<>'.inc' Then $file_save&='.inc'
    $file = FileOpen($file_save, 2)
    If $file = -1 Then
       MsgBox(0, "Error", "Unable to open file.")
       return
    EndIf
    $AllWindows = WinList()
    $sTmp = ""
    For $i = 1 To $AllWindows[0][0]
        If _IsVisible($AllWindows[$i][1]) And $AllWindows[$i][0] <> "" And $AllWindows[$i][0] <> "Program Manager" And StringRight(_ProcessGetPath(WinGetProcess($AllWindows[$i][0])), 12)='explorer.exe' Then
            If $sTmp = "" Then
                $sTmp &= ControlGetText ( $AllWindows[$i][0], '', "[CLASS:Edit; INSTANCE:1]")
            Else
                $sTmp &= "|"&ControlGetText ( $AllWindows[$i][0], '', "[CLASS:Edit; INSTANCE:1]")
            EndIf
        EndIf
    Next
    FileWrite($file, $sTmp)
    FileClose($file)
    _restart()
EndFunc  ;==>_save

Func _edit()
    Local $n = _ArraySearch($avTrayItems, @TRAY_ID, 1)
    If @error Then
        MsgBox(0, "Error", 'Not found ID')
        Exit
    EndIf
        $n+=1
    $file_open0=$avTrayItems[$n]
EndFunc  ;==>_allfolder

Func _allfolder()
    Local $n = _ArraySearch($avTrayItems, @TRAY_ID, 1)
    If @error Then
        MsgBox(0, "Error", 'Not found ID')
        Exit
    EndIf
        $n+=1
For $i = 1 To 35
    $z = _ArraySearch($avTrayItems, $avTrayItems[$n]&'_'&$i, 1)
    If @error Then ExitLoop
    $z-=1
    If Not FileExists($avTrayItems[$z]) Then ExitLoop
    Run('Explorer.exe "'&$avTrayItems[$z]&'"')
Next
EndFunc  ;==>_allfolder

Func _TrayItemHit()
    Local $i = _ArraySearch($avTrayItems, @TRAY_ID, 1)
    If @error Then
        MsgBox(16, "Error", 'Not found ID')
        Exit
    EndIf
        $i+=1
    If Not FileExists($avTrayItems[$i]) Then
        MsgBox(16, "Error", "no dir")
        Return
    EndIf
    Run('Explorer.exe "'&$avTrayItems[$i]&'"')
EndFunc  ;==>_TrayItemHit

Func _IsVisible($handle)
    If BitAND(WinGetState($handle), 4) and BitAND(WinGetState($handle), 2) Then
            Return 1
        Else
            Return 0
    EndIf
EndFunc  ;==>_IsVisible

Func _ProcessGetPath($PID)
    If IsString($PID) Then $PID = ProcessExists($PID)
    $Path = DllStructCreate('char[1000]')
    $dll = DllOpen('Kernel32.dll')
    $handle1 = DllCall($dll, 'int', 'OpenProcess', 'dword', 0x0400 + 0x0010, 'int', 0, 'dword', $PID)
    $ret = DllCall('Psapi.dll', 'long', 'GetModuleFileNameEx', 'long', $handle1[0], 'int', 0, 'ptr', DllStructGetPtr($Path), 'long', DllStructGetSize($Path))
    $ret = DllCall($dll, 'int', 'CloseHandle', 'hwnd', $handle1[0])
    DllClose($dll)
    Return DllStructGetData($Path, 1)
EndFunc  ;==>_ProcessGetPath

Func _close()
    $AllWindows = WinList()
    $sTmp = ""
    For $i = 1 To $AllWindows[0][0]
        If _IsVisible($AllWindows[$i][1]) And $AllWindows[$i][0] <> "" And $AllWindows[$i][0] <> "Program Manager" And StringRight(_ProcessGetPath(WinGetProcess($AllWindows[$i][0])), 12)='explorer.exe' Then
                WinClose($AllWindows[$i][0])
        EndIf
    Next
EndFunc  ;==>_close

Func _restart()
    Local $sAutoIt_File = @TempDir & "\~Au3_ScriptRestart_TempFile.au3"
    Local $sRunLine, $sScript_Content, $hFile
    
    $sRunLine = @ScriptFullPath
    If Not @Compiled Then $sRunLine = @AutoItExe & ' /AutoIt3ExecuteScript ""' & $sRunLine & '""'
    If $CmdLine[0] > 0 Then $sRunLine &= ' ' & $CmdLineRaw
    
    $sScript_Content &= '#NoTrayIcon' & @CRLF & _
    'While ProcessExists(' & @AutoItPID & ')' & @CRLF & _
    '   Sleep(10)' & @CRLF & _
    'WEnd' & @CRLF & _
    'Run("' & $sRunLine & '")' & @CRLF & _
    'FileDelete(@ScriptFullPath)' & @CRLF
    
    $hFile = FileOpen($sAutoIt_File, 2)
    FileWrite($hFile, $sScript_Content)
    FileClose($hFile)
    
    Run(@AutoItExe & ' /AutoIt3ExecuteScript "' & $sAutoIt_File & '"', @ScriptDir, @SW_HIDE)
    Sleep(1000)
    Exit
EndFunc  ;==>_restart

Func _Quit()
    Exit
EndFunc
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...