Sign in to follow this  
Followers 0
ricky

Window doesn't close

3 posts in this topic

#1 ·  Posted (edited)

Hello,

I extract a peace of a script made by AZJIO , but my windows never close and I don't understand why.

Could you help me?

AB-06410.txt

Thanks in advance

Edited by ricky03

Share this post


Link to post
Share on other sites



ricky03,

See the comments in code...

#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w 7
#include <GuiImageList.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>

#include <GuiTreeView.au3>
#include <Array.au3>

Local $Gui1, $sList, $iBtnSave, $hTreeView, $g_hImgAssot, $tree

Local $g_aExtAssot[1] = [0]
Local $g_aExtBlack[6] = [5, 'exe', 'scr', 'ico', 'ani', 'cur']

Local $aListTree[3]
$aListTree[0] = '|' & @TAB ; IniRead($ini, 'List', 'Depth', '|' & @Tab)
$aListTree[1] = '+----' ; IniRead($ini, 'List', 'Folder', '+----')
$aListTree[2] = '-----' ; IniRead($ini, 'List', 'File', '-----')

; En
Global $aLngEn[10]= [9, _
        'Open the file to read', _
        'All', _
        'List', _
        'View a list', _
        'List', _
        'item', _
        'sec', _
        'Open new', _
        'Do you want to open a new file?']

Global $aLng[10] = [9]

For $i = 1 To $aLng[0]
    $aLng[$i] = $aLngEn[$i]
Next

_ViewListFiles()

Func _ViewListFiles()

    Local $aLastPath, $aList, $sep, $n_Return, $timer, _
            $aLastPath[100][3] = [[0]]

    $Gui1 = GUICreate($aLng[4], 800, 530, -1, -1)
    If Not @Compiled Then GUISetIcon(@ScriptDir & '\Create_list_files.ico')

    $tree = GUICtrlCreateTreeView(0, 0, 800, 530, -1, $WS_EX_CLIENTEDGE)
    GUICtrlSetResizing(-1, 2 + 4 + 32)
    $hTreeView = ControlGetHandle($Gui1, "", $tree)

    $g_hImgAssot = _GUIImageList_Create(16, 16, 5, 1) ; Créer une liste d'icônes
    _GUIImageList_AddIcon($g_hImgAssot, @SystemDir & '\shell32.dll', -4)
    _GUIImageList_AddIcon($g_hImgAssot, @SystemDir & '\shell32.dll', 0)
    _GUICtrlTreeView_SetNormalImageList($hTreeView, $g_hImgAssot)

    $sep = Opt("GUIDataSeparatorChar", "\")
    $timer = TimerInit()

    Local $fileName = "", $s_Tree = "", $s_TreeTemp = "", $n_Files = 0

    do
        if $s_Tree <> "" Then $s_Tree &= "|"
        $aList = openFile($fileName)
        $n_Files += $aList[0]
        $s_TreeTemp = $aLng[5] & " (" & $aList[0] & " files) - " & $fileName
        $aLastPath[0][1] = _GUICtrlTreeView_Add($hTreeView, 0, $s_TreeTemp, 0, 0) ; ajouter l'élément racine
        $s_Tree &= $s_TreeTemp
        _AddFileList($aList, $aLastPath, $hTreeView)
        $n_Return = MsgBox(4 + 32,$aLng[8], $aLng[9])
    Until $n_Return = 7

    WinSetTitle($Gui1, '', $aLng[4] & ' (' & $n_Files & ' ' & $aLng[6] & ' ' & Round(TimerDiff($timer) / 1000, 2) & ' ' & $aLng[7] & ')')
    Opt("GUIDataSeparatorChar", $sep)

    $s_TreeTemp = StringSplit($s_Tree,"|")
    For $i = 1 to $s_TreeTemp[0]
        ControlTreeView($Gui1, '', $hTreeView, 'Expand', $s_TreeTemp[$i])
    Next

    GUISetState(@SW_SHOW, $Gui1)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ;ExitLoop
                guidelete($Gui1)
                Exit    ; <-----

        EndSwitch

        ;Sleep(2000)    no need to idle the loop

    WEnd

    ;GUIDelete($Gui1) this has no effect here if exiting

EndFunc   ;==>_ViewListFiles

Func openFile(byref $fileName)

    Local $a_List, $s_Temp
    Local $ListFile = FileOpenDialog($aLng[1], @ScriptDir, $aLng[2] & ' (*.txt)', 3, $aLng[3])
    If @error Then Return
    $s_Temp = StringSplit($ListFile,"\")
    $fileName = $s_Temp[$s_Temp[0]]
    $a_List = StringSplit(StringReplace(FileRead($ListFile), ';', ' ; '), @CRLF, 1) ; Lire la liste dans un tableau
    _ArraySort($a_List, 0, 1)
    Return $a_List

EndFunc

Func __TreeViewToText($hItem, $sIndent)
    $hItem = _GUICtrlTreeView_GetFirstChild($hTreeView, $hItem) ; Demande le premier élément enfant
    If Not $hItem Then Return
    Local $f, $fFlag, $tmp = $sIndent & $aListTree[0]
    Do
        $fFlag = _GUICtrlTreeView_GetChildren($hTreeView, $hItem)
        If $fFlag Then
            $f = $aListTree[1]
        Else
            $f = $aListTree[2]
        EndIf

        $sList &= $sIndent & $f & _GUICtrlTreeView_GetText($hTreeView, $hItem) & @CRLF
        If $fFlag Then
            __TreeViewToText($hItem, $tmp)
        EndIf
        $hItem = _GUICtrlTreeView_GetNextSibling($hTreeView, $hItem) ; Demande l'article suivant
    Until Not $hItem
EndFunc   ;==>__TreeViewToText

Func _AddFileList($aList, ByRef $aLastPath, $hTreeView)
    Local $hItem, $i, $ind, $j, $tmp, $ext, $z, $splitFile
    For $z = 1 To $aList[0]
        $tmp = StringSplit($aList[$z], '\') ; Division du chemin
        For $i = 1 To $tmp[0]
            If $tmp[$i] <> $aLastPath[$i][0] Then
                For $j = $i To $tmp[0]
                    $aLastPath[$j][0] = $tmp[$j] ; mise en cache le nouveau chemin
                    $aLastPath[$j + 1][2] = 0 ; remettre le compteur à 0 (dossiers)
                Next
                ExitLoop
            EndIf
        Next
        For $i = $i To $tmp[0]
            If $i = $tmp[0] Then
                $splitFile = StringSplit($tmp[$i], ' ; ')
                $ext = StringRegExpReplace($splitFile[1], '.+\.(\w+)$', '\1') ; recherche d'extension
                $ind = _Get_Num_ICO($ext)
                If @error Then $ind = 0
                $aLastPath[$i][1] = _GUICtrlTreeView_AddChild($hTreeView, $aLastPath[$i - 1][1], $tmp[$i], $ind + 1, $ind + 1) ; ajoute l'article (fichier) à la fin de la liste
            Else
                $ind = 0
                ; si c'est un dossier
                If $aLastPath[$i][2] Then
                    $hItem = _GUICtrlTreeView_GetItemByIndex($hTreeView, $aLastPath[$i - 1][1], $aLastPath[$i][2] - 1)
                    $aLastPath[$i][1] = _GUICtrlTreeView_InsertItem($hTreeView, $tmp[$i], $aLastPath[$i - 1][1], $hItem, $ind, $ind)
                Else ; sinon, si l'indice est 0, ajouter le haut de la liste
                    $aLastPath[$i][1] = _GUICtrlTreeView_AddChildFirst($hTreeView, $aLastPath[$i - 1][1], $tmp[$i], $ind, $ind) ; ajouter un item
                EndIf
                $aLastPath[$i][2] += 1
            EndIf
        Next
    Next
EndFunc   ;==>_AddFileList

Func _Get_Num_ICO($sExt)
    ; Global $g_hImgAssot
    ; Global $g_aExtAssot
    Local $ind, $ico1
    $ind = _ArraySearch2($g_aExtAssot, $sExt)
    If @error Then
        $ico1 = _FileDefaultIcon('.' & $sExt)
        If @error Then
            Return SetError(1, 0, -1)
        Else
            Switch UBound($ico1)
                Case 2
                    If _ArraySearch2($g_aExtBlack, $sExt) > 0 Then ; Si dans la liste noire, alors erreur
                        Return SetError(1, 0, -1)
                    Else
                        _GUIImageList_AddIcon($g_hImgAssot, $ico1[1], 0)
                        If @error Then
                            _ArrayAdd2($g_aExtBlack, $sExt) ; Si erreur, ajouter l'extension à la liste noire
                            Return SetError(1, 0, -1)
                        EndIf
                    EndIf
                Case 3
                    _GUIImageList_AddIcon($g_hImgAssot, $ico1[1], $ico1[2])
                    If @error Then
                        _ArrayAdd2($g_aExtBlack, $sExt) ; Si erreur, ajouter l'extension à la liste noire
                        Return SetError(1, 0, -1)
                    EndIf
            EndSwitch
            _ArrayAdd2($g_aExtAssot, $sExt) ; Sinon, ajouter l'extension à la liste blanche
            Return SetError(0, 0, $g_aExtAssot[0])
            ; MsgBox(4096, "Information", "Nombre d'images: " & _GUIImageList_GetImageCount($g_hImgAssot))
            ; $sText = ''
            ; For $i = 0 To $g_aExtAssot[0]
            ; $sText &= $g_aExtAssot[$i] & @LF
            ; Next
            ; MsgBox(0, 'Message', $sText)
        EndIf
    Else
        Return SetError(0, 0, $ind)
    EndIf
EndFunc   ;==>_Get_Num_ICO

Func _ArrayAdd2(ByRef $Array, $ext)
    $Array[0] += 1
    ReDim $Array[$Array[0] + 1]
    $Array[$Array[0]] = $ext
EndFunc   ;==>_ArrayAdd2

Func _ArraySearch2(ByRef $Array, $ext)
    For $i = 1 To $Array[0]
        If $ext = $Array[$i] Then Return SetError(0, 0, $i)
    Next
    Return SetError(1, 0, -1)
EndFunc   ;==>_ArraySearch2

Func _FileDefaultIcon($sExt)
    If $sExt = '' Or StringInStr($sExt, ':') Then Return SetError(1)

    Local $aCall = DllCall("shlwapi.dll", "int", "AssocQueryStringW", _
            "dword", 0x00000040, _ ;$ASSOCF_VERIFY
            "dword", 15, _ ;$ASSOCSTR_DEFAULTICON
            "wstr", $sExt, _
            "ptr", 0, _
            "wstr", "", _
            "dword*", 65536)

    If @error Then Return SetError(1, 0, "")

    If Not $aCall[0] Then
        $sExt = StringReplace($aCall[5], '"', '')
        $sExt = StringSplit($sExt, ',')
        Opt('ExpandEnvStrings', 1)
        $sExt[1] = $sExt[1]
        Opt('ExpandEnvStrings', 0)
        Return SetError(0, 0, $sExt)
    ElseIf $aCall[0] = 0x80070002 Then
        Return SetError(1, 0, "{unknown}")
    ElseIf $aCall[0] = 0x80004005 Then
        Return SetError(1, 0, "{fail}")
    Else
        Return SetError(2, $aCall[0], "")
    EndIf
EndFunc   ;==>_FileDefaultIcon

;~ Func FileGetIcon(ByRef $szIconFile, ByRef $nIcon, $szExt)
;~     Dim $szRegDefault = "", $szDefIcon = ""
;~     $nIcon = 0
;~     If $szRegDefault = "" Then $szRegDefault = RegRead("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\" & $szExt, "ProgID")
;~     If $szRegDefault = "" Then $szRegDefault = RegRead("HKCR\." & $szExt, "")
;~     If $szRegDefault <> "" Then $szDefIcon = RegRead("HKCR\" & $szRegDefault & "\DefaultIcon", "")
;~     If $szDefIcon = "" Then
;~         $szIconFile = "shell32.dll"
;~     ElseIf $szDefIcon <> "%1" Then
;~         $arSplit = StringSplit($szDefIcon, ",")
;~         If IsArray($arSplit) Then
;~             $szIconFile = FileGetLongName(StringReplace($arSplit[1], '"', ''))
;~             If $arSplit[0] > 1 Then $nIcon = $arSplit[2]
;~             If StringInStr($arSplit[1], "shell32.dll") Then $nIcon += 81
;~         Else
;~             Return 0
;~         EndIf
;~     EndIf
;~     Return 1
;~ EndFunc   ;==>FileGetIcon

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

Thanks for your help.

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