Jump to content
Sign in to follow this  
xtcislove

TreeView color file and belonging tree

Recommended Posts

Hello,

i stuck again,

Im using this function to create a treeview from root dir.
 

;https://autoit.de/index.php?thread/86082-treeview-root-verbergen/&postID=691139#post691139
#include <File.au3>
#include <WindowsConstants.au3>

Global $sPath = @ScriptDir
Global $hGui = GUICreate('TreeView-Example', 400, 600)
Global $idTreeView = GUICtrlCreateTreeView(10, 10, 380, 580, Default, $WS_EX_CLIENTEDGE)
GUISetState()
_CreatePath($sPath, $idTreeView)
Do
Until GUIGetMsg() = -3

Func _CreatePath($sPath, $idParent)
    Local $aFolder, $aFiles, $idItem
    If StringRight($sPath, 1) <> '\' Then $sPath &= '\'
    $aFolder = _FileListToArray($sPath, '*', $FLTA_FOLDERS)
    If Not @error Then
        For $i = 1 To $aFolder[0]
            $idItem = GUICtrlCreateTreeViewItem($aFolder[$i], $idParent)
            _CreatePath($sPath & $aFolder[$i], $idItem)
        Next
    EndIf
    $aFiles = _FileListToArray($sPath, '*', $FLTA_FILES)
    If @error Then Return
    For $i = 1 To $aFiles[0]
        $idItem = GUICtrlCreateTreeViewItem($aFiles[$i], $idParent)
    Next
EndFunc

Folder Structure:

Folder1

Folder2

Folder3

If a file exists in multiple folders, i like to color it red, if not green. 

I know how to do this for files, but nut for the folders.

Because if there is only 1 file in Folder2 that is also in Folder1 that it should only color this single file red, inlcuding its whole tree.

The Folder1 and Folder2 should be red in this case, too. Other files and trees should stay green.

 

Edit:
Basically i like to color a file and its belonging tree red if the file exists more than 1 time.

Edited by xtcislove

Share this post


Link to post
Share on other sites

The color change for file and folders is the same, just use GUICtrlSetBkColor. Here the script a little enhanced:

;https://autoit.de/index.php?thread/86082-treeview-root-verbergen/&postID=691139#post691139
#include <File.au3>
#include <WindowsConstants.au3>
#include <GuiTreeView.au3>
#include <ColorConstants.au3>

;Global $sPath = @ScriptDir
Global $sPath = StringRegExpReplace(@AutoItExe, '(.+\\).+', '$1') ; <- als Beispiel das AutoIt-Verzeichnis
Global $hGui = GUICreate('TreeView-Example', 400, 600)
Global $idTreeView = GUICtrlCreateTreeView(10, 10, 380, 580, Default, $WS_EX_CLIENTEDGE)
GUISetState()
ToolTip('Verzeichnis wird eingelesen. Bitte warten!', Default, Default, 'TreeView-Example', $TIP_INFOICON, $TIP_BALLOON)
_GUICtrlTreeView_BeginUpdate($idTreeView)
_CreatePath($sPath, $idTreeView)
_GUICtrlTreeView_EndUpdate($idTreeView)
ToolTip('')
Do
Until GUIGetMsg() = -3

Func _CreatePath($sPath, $idParent)
    Local $aFolder, $aFiles, $idItem
    If StringRight($sPath, 1) <> '\' Then $sPath &= '\'
    $aFolder = _FileListToArray($sPath, '*', $FLTA_FOLDERS)
    If Not @error Then
        For $i = 1 To $aFolder[0]
            $idItem = GUICtrlCreateTreeViewItem($aFolder[$i], $idParent)
            If $aFolder[$i] = 'Scite' Then
                GUICtrlSetBkColor(-1, $COLOR_RED)
            Else
                GUICtrlSetBkColor(-1, $COLOR_Yellow)
            EndIf
            _CreatePath($sPath & $aFolder[$i], $idItem)
        Next
    EndIf
    $aFiles = _FileListToArray($sPath, '*', $FLTA_FILES)
    If @error Then Return
    For $i = 1 To $aFiles[0]
        $idItem = GUICtrlCreateTreeViewItem($aFiles[$i], $idParent)
        If StringInStr($aFiles[$i], 'Readme') Then
            GUICtrlSetBkColor(-1, $COLOR_RED)
        Else
            GUICtrlSetBkColor(-1, $COLOR_Yellow)
        EndIf
    Next
EndFunc   ;==>_CreatePath

it's only demostration (playing). If you want to know how to build the logic, than i must ask:

What's a duplicate file?

  • Same name
  • Same size
  • Same hash

Files with same name and size can be different, files with same hash most are real duplicates.

So i suggest try following example(s) in help:

  • _GUICtrlListView_SetItemParam
  • _Crypt_HashFile 

these will help to build a stable logic.

Edited by AutoBert

Share this post


Link to post
Share on other sites

@AutoBert

I like to check only by name. 
The path structures and filenames are unique. 

If a file is in Folder 1 and Folder 2 its in the same sub directorys.

Folder structure: (Edit: Colored for desired result)

Spoiler

;-> This is the folder i build my TreeView from.

Folder\

Folder 1\

Folder 2\

Folder 3\

;-< This is the folder i build my TreeView from.

Folder 1\
    characters\models\geralt\head\model\eye__geralt_d01.xbm
    characters\models\geralt\head\model\h_01_mg__geralt_d01.xbm
    characters\models\geralt\head\model\h_01_mg__geralt_d02.xbm
    characters\models\geralt\head\model\h_01_mg__geralt_n01.xbm
    characters\models\geralt\head\model\h_01_mg__geralt_n02.xbm
    characters\models\geralt\head\model\h_01_mg__geralt_tattoo_d01.xbm
    characters\models\geralt\head\model\ep1_mark\h_01_mg__geralt_d01_mark.xbm
    characters\models\geralt\head\model\ep1_mark\h_01_mg__geralt_d01_mark_tattoo.xbm
    characters\models\geralt\head\model\ep1_mark\h_01_mg__geralt_d02_mark.xbm
    characters\models\geralt\body\model\body_01_mg__geralt_d01.xbm

Folder 2\
    characters\models\geralt\head\model\eye__geralt_d01.xbm
    characters\models\geralt\head\model\h_01_mg__geralt_d01.xbm
    characters\models\geralt\head\model\h_01_mg__geralt_d02.xbm
    characters\models\geralt\head\model\h_01_mg__geralt_n01.xbm
    characters\models\geralt\head\model\h_01_mg__geralt_n02.xbm
    characters\models\geralt\head\model\h_01_mg__geralt_tattoo_d01.xbm

    characters\models\geralt\head\model\h_01_mg__geralt_tattoo_d02.xbm
    characters\models\geralt\head\model\h_02_mg__geralt_d01.xbm
    characters\models\geralt\head\model\h_02_mg__geralt_n01.xbm
    characters\models\geralt\head\model\h_03_mg__geralt_d01.xbm
    characters\models\geralt\head\model\h_03_mg__geralt_n01.xbm
    characters\models\geralt\head\model\h_04_mg__geralt_d01.xbm
    characters\models\geralt\head\model\h_04_mg__geralt_n01.xbm
    characters\models\geralt\head\model\ep1_mark\h_01_mg__geralt_d01_mark.xbm
    characters\models\geralt\head\model\ep1_mark\h_01_mg__geralt_d01_mark_tattoo.xbm
    characters\models\geralt\head\model\ep1_mark\h_01_mg__geralt_d02_mark.xbm

    characters\models\geralt\head\model\ep1_mark\h_01_mg__geralt_d02_mark_tattoo.xbm
    
characters\models\geralt\head\model\ep1_mark\h_01_mg__geralt_n01_mark.xbm
  
 characters\models\geralt\head\model\ep1_mark\h_01_mg__geralt_n02_mark.xbm
    characters\models\geralt\body\model\body_01_mg__geralt_d01.xbm
    characters\models\geralt\body\model\s_01_mg__body_hires_d01.xbm
Folder 3\
    dlc\dlc6\data\characters\models\main_npc\triss\model\body_01_wa__triss_dlc_d01.xbm
    dlc\dlc6\data\characters\models\main_npc\triss\model\body_01_wa__triss_dlc_s01.xbm
    dlc\dlc4\data\characters\models\main_npc\yennefer\model\body_05_wa__yennefer_d01.xbm
    dlc\dlc4\data\characters\models\main_npc\yennefer\model\body_05_wa__yennefer_d02.xbm
    dlc\dlc4\data\characters\models\main_npc\yennefer\model\glove_01_wa__yennefer_d01.xbm
    dlc\dlc4\data\characters\models\main_npc\yennefer\model\scarf_01_wa__yennefer_d01.xbm
    dlc\dlc4\data\characters\models\main_npc\yennefer\model\stockings_01_wa__yennefer_d01.xbm
    dlc\dlc4\data\characters\models\main_npc\yennefer\model\yennefer_feathers_d01.xbm
    dlc\dlc11\data\characters\models\main_npc\ciri\model\body_01_wa__ciri_dlc_d01.xbm
    dlc\dlc11\data\characters\models\main_npc\ciri\model\body_01_wa__ciri_dlc_d02.xbm
    dlc\dlc11\data\characters\models\main_npc\ciri\model\body_01_wa__ciri_dlc_d03.xbm
    dlc\dlc11\data\characters\models\main_npc\ciri\model\body_01_wa__ciri_dlc_s01.xbm
    dlc\dlc11\data\characters\models\main_npc\ciri\model\ciri_chainmail_dlc_d01.xbm
    dlc\dlc11\data\characters\models\main_npc\ciri\model\ciri_chainmail_dlc_n01.xbm
    characters\models\main_npc\yennefer\model\body_01_wa__yennefer.w2mesh
    characters\models\main_npc\yennefer\model\body_01_wa__yennefer.w2mesh.1.buffer
    characters\models\main_npc\yennefer\model\body_01_wa__yennefer_a01.xbm
    characters\models\main_npc\yennefer\model\body_01_wa__yennefer_a02.xbm
    characters\models\main_npc\yennefer\model\body_01_wa__yennefer_d01.xbm
    characters\models\main_npc\yennefer\model\body_01_wa__yennefer_d02.xbm
    characters\models\main_npc\yennefer\model\body_01_wa__yennefer_hooded.w2mesh
    characters\models\main_npc\yennefer\model\body_01_wa__yennefer_hooded.w2mesh.1.buffer
    characters\models\main_npc\yennefer\model\body_01_wa__yennefer_n01.xbm
    characters\models\main_npc\yennefer\model\body_01_wa__yennefer_n02.xbm
    characters\models\main_npc\yennefer\model\dress_01_wa__yennefer_a01.xbm
    characters\models\main_npc\yennefer\model\dress_01_wa__yennefer_a02.xbm
    characters\models\main_npc\yennefer\model\dress_01_wa__yennefer_d01.xbm
    characters\models\main_npc\yennefer\model\dress_01_wa__yennefer_d02.xbm
    characters\models\main_npc\yennefer\model\dress_01_wa__yennefer_n01.xbm
    characters\models\main_npc\yennefer\model\dress_01_wa__yennefer_n02.xbm
    characters\models\main_npc\yennefer\model\fur_01_wa__yennefer.w2mesh
    characters\models\main_npc\yennefer\model\fur_01_wa__yennefer.w2mesh.1.buffer
    characters\models\main_npc\yennefer\model\fur_01_wa__yennefer_a01.xbm
    characters\models\main_npc\yennefer\model\fur_01_wa__yennefer_d01.xbm
    characters\models\main_npc\yennefer\model\fur_01_wa__yennefer_n01.xbm
    characters\models\main_npc\yennefer\model\fur_02_wa__yennefer.w2mesh
    characters\models\main_npc\yennefer\model\fur_02_wa__yennefer.w2mesh.1.buffer
    characters\models\main_npc\yennefer\model\fur_03_wa__yennefer.w2mesh
    characters\models\main_npc\yennefer\model\fur_03_wa__yennefer.w2mesh.1.buffer
    characters\models\main_npc\yennefer\model\l_01_wa__yennefer.w2mesh
    characters\models\main_npc\yennefer\model\l_01_wa__yennefer.w2mesh.1.buffer
    characters\models\main_npc\yennefer\model\l_02_wa__yennefer.w2mesh
    characters\models\main_npc\yennefer\model\l_02_wa__yennefer.w2mesh.1.buffer
    characters\models\main_npc\yennefer\model\l_02_wa__yennefer_a01.xbm
    characters\models\main_npc\yennefer\model\l_02_wa__yennefer_d01.xbm
    characters\models\main_npc\yennefer\model\l_02_wa__yennefer_n01.xbm
    characters\models\main_npc\yennefer\model\yennefer__body_d_notcensor.xbm
    characters\models\main_npc\yennefer\model\yennefer__body_n_notcensor.xbm
    characters\models\main_npc\yennefer\h_01_wa__yennefer\eye__yennefer_d01.xbm
    characters\models\main_npc\yennefer\h_01_wa__yennefer\h_01_wa__yennefer_a01.xbm
    characters\models\main_npc\yennefer\h_01_wa__yennefer\h_01_wa__yennefer_b01.xbm
    characters\models\main_npc\yennefer\h_01_wa__yennefer\h_01_wa__yennefer_d01.xbm
    characters\models\main_npc\yennefer\h_01_wa__yennefer\h_01_wa__yennefer_n01.xbm
    characters\models\main_npc\triss\model\body_01_wa__triss_d01.xbm
    characters\models\main_npc\triss\model\body_02_wa__triss_d01.xbm
    characters\models\main_npc\triss\model\body_02_wa__triss_s01.xbm
    characters\models\main_npc\triss\model\body_03_wa__triss.w2mesh
    characters\models\main_npc\triss\model\body_03_wa__triss.w2mesh.1.buffer
    characters\models\main_npc\triss\model\body_03_wa__triss_a01.xbm
    characters\models\main_npc\triss\model\body_03_wa__triss_d01.xbm
    characters\models\main_npc\triss\model\body_03_wa__triss_n01.xbm
    characters\models\main_npc\triss\model\body_03_wa__triss_s01.xbm
    characters\models\main_npc\triss\model\i_03_wa__triss_d01.xbm
    characters\models\main_npc\triss\h_01_wa__triss\h_01_wa__triss_b01.xbm
    characters\models\main_npc\triss\h_01_wa__triss\h_01_wa__triss_d01.xbm
    characters\models\main_npc\triss\h_01_wa__triss\h_01_wa__triss_d02.xbm
    characters\models\main_npc\triss\h_01_wa__triss\h_01_wa__triss_d03.xbm
    characters\models\main_npc\triss\h_01_wa__triss\h_01_wa__triss_n01.xbm
    characters\models\main_npc\ciri\model\body_01_wa__ciri_d01.xbm
    characters\models\main_npc\ciri\model\body_01_wa__ciri_d02.xbm
    characters\models\main_npc\ciri\model\body_01_wa__ciri_d03.xbm
    characters\models\main_npc\ciri\model\body_01_wa__ciri_s01.xbm
    characters\models\main_npc\ciri\model\body_01_wa__ciri_s03.xbm
    characters\models\main_npc\ciri\model\body_03__wa_ciri_a01.xbm
    characters\models\main_npc\ciri\model\body_03__wa_ciri_d01.xbm
    characters\models\main_npc\ciri\model\body_03__wa_ciri_n01.xbm
    characters\models\main_npc\ciri\model\body_05_wa__ciri_d01.xbm
    characters\models\main_npc\ciri\model\collar_01_wa__ciri_d01.xbm
    characters\models\main_npc\ciri\model\item_07_wa__ciri_d01.xbm
    characters\models\main_npc\ciri\model\item_10_wa__ciri_d01.xbm
    characters\models\main_npc\ciri\model\l_01_wa__lingerie_ciri.w2mesh
    characters\models\main_npc\ciri\model\l_01_wa__lingerie_ciri.w2mesh.1.buffer
    characters\models\main_npc\ciri\h_01_wa__ciri\eye__ciri_d01.xbm
    characters\models\main_npc\ciri\h_01_wa__ciri\eye__ciri_d02.xbm
    characters\models\main_npc\ciri\h_01_wa__ciri\h_01_wa__ciri_a01.xbm
    characters\models\main_npc\ciri\h_01_wa__ciri\h_01_wa__ciri_a02.xbm
    characters\models\main_npc\ciri\h_01_wa__ciri\h_01_wa__ciri_a03.xbm
    characters\models\main_npc\ciri\h_01_wa__ciri\h_01_wa__ciri_a04.xbm
    characters\models\main_npc\ciri\h_01_wa__ciri\h_01_wa__ciri_b01.xbm
    characters\models\main_npc\ciri\h_01_wa__ciri\h_01_wa__ciri_d01.xbm
    characters\models\main_npc\ciri\h_01_wa__ciri\h_01_wa__ciri_d02.xbm
    characters\models\main_npc\ciri\h_01_wa__ciri\h_01_wa__ciri_d03.xbm
    characters\models\main_npc\ciri\h_01_wa__ciri\h_01_wa__ciri_d04.xbm
    characters\models\main_npc\ciri\h_01_wa__ciri\h_01_wa__ciri_n01.xbm
    characters\models\main_npc\ciri\h_01_wa__ciri\h_01_wa__ciri_n02.xbm
    characters\models\main_npc\ciri\h_01_wa__ciri\h_01_wa__ciri_n03.xbm
    characters\models\main_npc\ciri\h_01_wa__ciri\h_01_wa__ciri_n04.xbm


So i am able to check if a file is in more than one folder and color it red instead of green, but i dont know how to paint the sub directorys red, it is in.
 

Edited by xtcislove

Share this post


Link to post
Share on other sites

My function for finding duplicated files: 

Func _FindDuplicates($sPath)
    Local $aFolder, $aFiles, $aFind, $aRet
    $aFolder = _FileListToArrayRec($sPath, "*", 1, 1, 0, 1)
    $aFiles = _FileListToArrayRec($sPath, "*", 1, 1, 0, 0)
    For $i = 1 To $aFiles[0]
        $aFind = _ArrayFindAll($aFiles, $aFiles[$i])
        If UBound($aFind) <> 1 Then $aRet &= $aFolder[$i] & "|"
    Next
    $aRet = StringSplit(StringTrimRight($aRet, 1), "|")
    Return $aRet
EndFunc

This will return all "trees" that need to be colored red.

 array.PNG.e2d9356767d5bd97ae7f212b388ac6c7.PNG

I could loop trough each line of this array and split each line by "\" but that would also color the characters folder red in Folder_3, too.

I was thinking of using GUICtrlCreateDummy() or to handle each TreeView Item in a array and if the file is a duplicate i could loop trough GUICtrlCreateDummy() or the array, but that wouldnt work either, since the CreatePath function, loops torugh each folder and not the whole tree.

Edited by xtcislove

Share this post


Link to post
Share on other sites

So i found out how to build an array from every folder/file with its Handle:

But i dont know how to use it and the structure is not quiet right.

array.thumb.PNG.92dbc3e6527bb1450cba3cf3f80f5eb9.PNG

 

Func _CreatePath($sPath, $idParent)
    Local $aFolder, $aFiles, $idItem
    If StringRight($sPath, 1) <> '\' Then $sPath &= '\'
    $aFolder = _FileListToArray($sPath, '*', $FLTA_FOLDERS)
    If Not @error Then
        For $i = 1 To $aFolder[0]

            $aAllItem[0][0] += 1
            ReDim $aAllItem[$aAllItem[0][0]+1][3]
            Local $sItemName = _StripPath($aFolder[$i])

            $idItem = GUICtrlCreateTreeViewItem($aFolder[$i], $idParent)
            GUICtrlSetColor(-1, 0x098902)
            GUICtrlSetImage(-1, "shell32.dll", 4)

            $aAllItem[$aAllItem[0][0]][0] = $idItem
            $aAllItem[$aAllItem[0][0]][1] = $sItemName

            _CreatePath($sPath & $aFolder[$i], $idItem)
        Next
    EndIf
    $aFiles = _FileListToArray($sPath, '*', $FLTA_FILES)
    If @error Then Return
    For $i = 1 To $aFiles[0]

        $aAllItem[0][0] += 1
        ReDim $aAllItem[$aAllItem[0][0]+1][3]
        Local $sItemName = _StripPath($aFiles[$i])

        $idItem = GUICtrlCreateTreeViewItem($aFiles[$i], $idParent)
        GUICtrlSetImage(-1, @ScriptDir & "\tools\icon.ico")
        GUICtrlSetColor(-1, 0x098902)

        $aAllItem[$aAllItem[0][0]][0] = $idItem
        $aAllItem[$aAllItem[0][0]][1] = $sItemName

    Next
EndFunc

 

Share this post


Link to post
Share on other sites
On 3.9.2018 at 10:32 PM, LarsJ said:

Have you made it work? It's not impossible.

Yeah i made it, but not a good solution i think...

 

Func _FindDuplicates($sPath)
    Local $aFiles, $aFind, $aRet
    $aFiles = _FileListToArrayRec($sPath, "*", 1, 1, 0, 0)
    For $i = 1 To $aFiles[0]
        $aFind = _ArrayFindAll($aFiles, $aFiles[$i])
        If UBound($aFind) <> 1 Then
            If Not StringInStr($aRet, $aFiles[$i]) Then $aRet &= $aFiles[$i] & "|"
        EndIf
    Next
    $aRet = StringSplit(StringTrimRight($aRet, 1), "|")
    Return $aRet
EndFunc

Func _CreateTreeView($sPath, $idParent, $aDupl)
    Local $aFolder, $aFiles, $idItem, $aPath
    If StringRight($sPath, 1) <> '\' Then $sPath &= '\'
    $aFolder = _FileListToArray($sPath, '*', $FLTA_FOLDERS)
    If Not @error Then
        For $i = 1 To $aFolder[0]
            $idItem = GUICtrlCreateTreeViewItem($aFolder[$i], $idParent)
            GUICtrlSetImage($idItem, "shell32.dll", 4)
            GUICtrlSetColor($idItem, 0x098902)
            $aPath = _FileListToArrayRec($sPath & $aFolder[$i], "*", 1, 1, 0, 0)
            If IsArray($aPath) Then
                For $s = 1 To $aPath[0]
                    _ArraySearch($aDupl, $aPath[$s])
                    If Not @error Then GUICtrlSetColor($idItem, 0xf41e0e)
                Next
            EndIf
            _CreateTreeView($sPath & $aFolder[$i], $idItem, $aDupl)
        Next
    EndIf
    $aFiles = _FileListToArray($sPath, '*', $FLTA_FILES)
    If @error Then Return
    For $i = 1 To $aFiles[0]
        $idItem = GUICtrlCreateTreeViewItem($aFiles[$i], $idParent)
        GUICtrlSetImage($idItem, @ScriptDir & "\tools\icon.ico")
        GUICtrlSetColor($idItem, 0x098902)
        _ArraySearch($aDupl, $aFiles[$i])
        If Not @error Then GUICtrlSetColor($idItem, 0xf41e0e)
    Next
EndFunc

 

Share this post


Link to post
Share on other sites

This is a way it can be done. The treeview is created with your code from a previous post. A dictionary object is used to find file duplicates. In case of duplicates, ItemParam is set to the value 1 all way up through the treeview. In custom draw code, items with ItemParam = 1 are drawn with red background color. Otherwise green.

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6

Opt( "MustDeclareVars", 1 )

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiTreeView.au3>

Global $hTreeView, $oDict = ObjCreate( "Scripting.Dictionary" )

Example()

Func Example()
  ; Create GUI
  Local $hGui = GUICreate( "Demo1", 620, 420 )

  ; Create TreeView
  $hTreeView = _GUICtrlTreeView_Create( $hGui, 10, 10, 600, 400, $TVS_HASBUTTONS+$TVS_HASLINES+$TVS_LINESATROOT+$TVS_DISABLEDRAGDROP+$TVS_SHOWSELALWAYS, $WS_EX_CLIENTEDGE )

  ; WM_NOTIFY message handler
  GUIRegisterMsg( $WM_NOTIFY, "WM_NOTIFY" )

  ; Show GUI
  GUISetState()

  ; Fill TreeView
  _GUICtrlTreeView_BeginUpdate( $hTreeView )
  ListFiles_ToTreeView( @ScriptDir & "\f", 0 )
  _GUICtrlTreeView_EndUpdate( $hTreeView )

  ; Loop
  While 1
    Switch GUIGetMsg()
      Case $GUI_EVENT_CLOSE
        ExitLoop
    EndSwitch
  WEnd

  ; Cleanup
  GUIDelete()
EndFunc

Func ListFiles_ToTreeView( $sSourceFolder, $hItem )
  ; Force a trailing \
  If StringRight( $sSourceFolder, 1 ) <> "\" Then $sSourceFolder &= "\"

  ; Start the search
  Local $hSearch = FileFindFirstFile( $sSourceFolder & "*.*" )
  ; If no files found then return
  If $hSearch = -1 Then Return ; This is where we break the recursive loop <<<<<<<<<<<<<<<<<<<<<<<<<<

  ; Now run through the contents of the folder
  Local $sFile, $hFile
  While 1
    ; Get next match
    $sFile = FileFindNextFile( $hSearch )
    ; If no more files then close search handle and return
    If @error Then ExitLoop ; This is where we break the recursive loop <<<<<<<<<<<<<<<<<<<<<<<<<<

    ; Check if a folder
    If @extended Then
      ; If so then call the function recursively
      ListFiles_ToTreeView( $sSourceFolder & $sFile, _GUICtrlTreeView_AddChild( $hTreeView, $hItem, $sFile ) )
    Else
      ; If a file than write path and name
      $hFile = _GUICtrlTreeView_AddChild( $hTreeView, $hItem, $sFile )
      If $oDict.Exists( $sFile ) Then
        ; File exists in another folder
        ; Set second, third, ... files red
        While $hFile
          _GUICtrlTreeView_SetItemParam( $hTreeView, $hFile, 1 ) ; Red
          $hFile = _GUICtrlTreeView_GetParentHandle( $hTreeView, $hFile )
        WEnd
        If $oDict( $sFile ) Then
          ; Set first file red
          $hFile = $oDict( $sFile )
          While $hFile
            _GUICtrlTreeView_SetItemParam( $hTreeView, $hFile, 1 ) ; Red
            $hFile = _GUICtrlTreeView_GetParentHandle( $hTreeView, $hFile )
          WEnd
          $oDict( $sFile ) = 0 ; Set first file red only once
        EndIf
      Else
        $oDict( $sFile ) = $hFile ; To be able to set first file red
      EndIf
    EndIf
  WEnd

  ; Close search handle
  FileClose( $hSearch )
EndFunc

Func WM_NOTIFY( $hWnd, $iMsg, $wParam, $lParam )
  Local $tNMHDR = DllStructCreate( $tagNMHDR, $lParam )
  Local $hWndFrom = HWnd( DllStructGetData( $tNMHDR, "hWndFrom" ) )
  Local $iCode = DllStructGetData( $tNMHDR, "Code" )

  Switch $hWndFrom
    Case $hTreeView
      Switch $iCode
        Case $NM_CUSTOMDRAW
          Local $tNMTVCUSTOMDRAW = DllStructCreate( $tagNMTVCUSTOMDRAW, $lParam )
          Local $dwDrawStage = DllStructGetData( $tNMTVCUSTOMDRAW, "DrawStage" )
          Switch $dwDrawStage              ; Specifies the drawing stage
            Case $CDDS_PREPAINT           ; Before the paint cycle begins
              Return $CDRF_NOTIFYITEMDRAW ; Item-related drawing operations
            Case $CDDS_ITEMPREPAINT        ; Before painting an item
              Local $iItemParam = DllStructGetData( $tNMTVCUSTOMDRAW, "ItemParam" )
              If $iItemParam Then
                DllStructSetData( $tNMTVCUSTOMDRAW, "ClrTextBk", 0xCCCCFF )  ; Red, BGR
              Else
                DllStructSetData( $tNMTVCUSTOMDRAW, "ClrTextBk", 0xCCFFCC )  ; Green
              EndIf
              Return $CDRF_NEWFONT        ; Return $CDRF_NEWFONT after changing colors
          EndSwitch
      EndSwitch
  EndSwitch

  Return $GUI_RUNDEFMSG
  #forceref $hWnd, $iMsg, $wParam
EndFunc

The zip-file contains the code and a simpel file/folder structure to test it.

tv.7z

Edited by LarsJ

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  

  • Similar Content

    • By DannyJ
      Hello Forum, 
      I have one special Combo-box [with BitOR($CBS_DROPDOWNLIST, $GUI_SS_DEFAULT_COMBO, $CBS_SIMPLE) ] and if I press one button I want to change the Combo-box's background color, and after I press Button B I want to change it to the basic settings and it not works.
      I wanna do this with one combo-box.
      I have already tried several methods and I tried  GUICtrlComboSetColors that I have found on this forum.
      (But this methods works perfectly with Cobo boxes that don't have BitOR($CBS_DROPDOWNLIST, $GUI_SS_DEFAULT_COMBO, $CBS_SIMPLE). 
      Here is the example code
      #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= ;$CBS_DROPDOWNLIST ;$GUI_SS_DEFAULT_COMBO $Form1 = GUICreate("Form1", 504, 249, 252, 227) $Combo1 = GUICtrlCreateCombo("", 136, 24, 193, 25,BitOR($CBS_DROPDOWNLIST, $GUI_SS_DEFAULT_COMBO, $CBS_SIMPLE)) ; I want to change this special combo's background color if I press button 1 $Button1 = GUICtrlCreateButton("Button1", 112, 96, 75, 25) $Button2 = GUICtrlCreateButton("Button2", 264, 96, 75, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### GUICtrlSetData($Combo1," " & "|" & "apple" & "|" & "banana" & "|" & "cherry" ," ") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 GUICtrlSetBkColor($Combo1,0x0078D7) Case $Button2 ;Makes the original bc color GUICtrlSetBkColor($Combo1,0xFFFFFF) EndSwitch WEnd  
      Thanks you in advance your help
    • By user4157124
      ConsoleWrite('>Message here.' & @CRLF) outputs colored text (per + > - ! characters).
      ConsoleWrite('warning' & @TAB & '38' & @TAB & 'more text ...' & @CRLF) enables jump to line 38 on doubleclick.

      Using "jump to line" format, only red and pink text coloring seems possible (simply prefixing color directives to output-text disables jump to line functionality). Is it possible to combine the two (define custom color while keeping "jump to line" functionality)?
    • By Miliardsto
      I have the following code. You can see there are $color_normal and $color_trans
      In my case normal is too dark . And color trans is to much violet.
      If you run it you will see how its looks. I want gui with listView have the same color like taskbar in windows 10.
      How to achieve that?
       
       
      #include <Date.au3> #include <MsgBoxConstants.au3> #include <GuiListBox.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <GuiListView.au3> HotKeySet("{ESC}", "Terminate") $color_normal = "0x" & StringLeft(StringRight(RegRead("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Accent", "AccentPalette"), 24), 6) $color_trans = "0x" & StringLeft(StringRight(RegRead("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Accent", "AccentPalette"), 16), 6) $trans = RegRead("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize", "EnableTransparency") ConsoleWrite("Transpart = " & $trans & @CRLF) ConsoleWrite("Color normal = " & $color_normal & @CRLF) ConsoleWrite("Color trans = " & $color_trans & @CRLF) ConsoleWrite(_Get_taskbar_color()); It return AARRGGBB $taskbarColor = _Get_taskbar_color() Global $gui = GUICreate("Test", 150, 58,@DesktopWidth-300,@DesktopHeight-58,$WS_POPUP,BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW)) Global $idListview = GUICtrlCreateListView("", 0, 0, 150, 58,BitOR($LBS_NOTIFY,$LBS_SORT), 0) ;_GuiCtrlMakeTrans(-1,100) ; Add column _GUICtrlListView_AddColumn($idListview, "Msgs", 100) GUICtrlSetFont(-1, 7, 400, 0, "Segoe UI") GUICtrlSetColor(-1, 0x470C4F) GUICtrlSetBkColor($idListview, 0x310638) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func Terminate() Exit EndFunc Func _Get_taskbar_color() If RegRead("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize", "ColorPrevalence") Then If RegRead("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize", "EnableTransparency") Then Return "0xD9" & StringLeft(StringRight(RegRead("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Accent", "AccentPalette"), 16), 6) Else Return "0xFF" & StringLeft(StringRight(RegRead("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Accent", "AccentPalette"), 24), 6) EndIf Else If RegRead("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize", "EnableTransparency") Then Return "0xD9000000" Else Return "0xFF000000" EndIf EndIf EndFunc  
    • By Burgs
      Hello,
        I am having great difficulty with something I would have thought to be fairly easy.  I have an array containing (military) organization strings, similar to this:
      42nd Battalion
       Company A
        1st Platoon
         1st Squad
         2nd Squad
         3rd Squad
        2nd Platoon
         ...1st, 2nd, 3rd Squad
        3rd Platoon
        ...1st, 2nd, 3rd Squad
       Company B
        ...etc...
      I also have an associated array that contains the 'hierarchy' information associated with each string..."0", "1","2", etc   ...therefore using example above the "0" would associate with "42nd Battalion", while "1" would be "Company A", "2" is "1st Platoon", etc.  Each sequential number is a 'child' of the preceding number.  Therefore the information above would appear in the array as "0", "1", "2", "3", "3", "3", "2", "3", "3", "3", "2", "3", "3", "3", "1", etc...
        My issue is that I'm having great difficulty creating a 'Treeview' control using this information.  Mainly due to the fact that entries can, and will...repeat (for example multiple entries for "Company A", "Company B", "1st Platoon", "1st Squad", etc, etc).  The following code is operative, however it does not create the treeview items as 'child' entries of one another...it simply lists each item as a separate entity.
      For $_populate = 0 to Ubound($_HIERARCHY) - 1 _GUICtrlTreeView_BeginUpdate($idTreeView) _GUICtrlTreeView_Add($idTreeView, $_HIERARCHY[$_populate], String($_STRUCTURES[$_populate])) _GUICtrlTreeView_EndUpdate($idTreeView) Next ;Next $_populate, cycle thru '$_HIERARCHY' array to build 'TREEVIEW' Controls As I mentioned earlier I thought I could manage this...however i'm pulling out quite a bit of my hair trying to get this working properly...any help would be appreciated.  I thank you in advance. 
       
    • By dejhost
      Happy New Year everyone!
      I would like to extract the color values of certain pixels in an image.  This is how I picture the workflow: 
      User opens an image of his choice. Image is shown on the screen. User draws a line into the image. This happens by marking the startpixel and the endpixel of the line The line is drawn, so the user can check visually if he is happy with the line.  The following pixel based properties belonging to the line are stored in Excel: X-Coordinate Y-Coordinate Color Value Additional operations: Extracting for max- and min. color values; Statistical operations.   Browsing through the helpfile of AutoIt I find plenty of functions for treating images (e.g. GDIPlus), but I am completely unsure if Autoit will get me there. Should I read the entire image into an array? Should I rather attempt to script an external image software (e.g. IrfanView, Gimp)?
      I would be very thankful if someone could give some recommendations and maybe list a couple of the most important commands to use.
      Thank you very much.
      Dejhost
       
       
×
×
  • Create New...