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 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
       
       
    • By Skeletor
      Hi All,
      While creating a few excel spreadsheets using AutoIt, I came across something which to my limiting time to research the forums I don't anyone has mentioned. 
      The color pallettes are reversed. 
      Huge shock to me.
       
      I wanted to produce a red row but kept on getting blue. 
      Seems like 0xFF0000 was red on the charts but when running the script, I got blue. 
      I then played around with the colors, and after a few tries, I finally got Red. 
      Reversed the FF0000 and the result is 0000FF.
       
      So for Excel compared to Html
      0000FF (Red) - Excel
      0000FF (Blue) - Html

      FFFF00 (Cyan) - Excel
      FFFF00(Yellow) - Html
       
    • By xtcislove
      Hello,

      im searching like 6 hours and i didnt found the right solution.

      Im trying to build a treeview from a directory and its subfolders etc.

      This function give me right treeview, but i cant color each item seperated.

       
      #include <GuiTreeView.au3> $hGui = GUICreate("Demo1", 600, 400) $hTreeView = _GUICtrlTreeView_Create($hGui, 10, 10, 580, 380) GUISetState() _GUICtrlTreeView_BeginUpdate($hTreeView) ListFiles_ToTreeView(@ScriptDir, 0) _GUICtrlTreeView_EndUpdate($hTreeView) Do Until GUIGetMsg() = -3 Func ListFiles_ToTreeView($sSourceFolder, $hItem) Local $sFile ; 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 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 _GUICtrlTreeView_AddChild($hTreeView, $hItem, $sFile) EndIf WEnd ; Close search handle FileClose($hSearch) EndFunc ;==>ListFiles_ToTreeView
      So i am searching for the exact same function just with
      GUICtrlCreateTreeViewItem
      instead of 
      _GUICtrlTreeView_AddChild
       
      Ps: i have a folder structure where i like to color each item green if a file only exist once and red if it exist more than once.

      Could someone help?
       
      Solution:

       
       
    • By Sven-Seyfert
      Hi Community,

      I have a problem with the usage of _GUICtrlTreeView_AddChild and setting different item text colors (and different background colors), separately for the TreeView levels.

      I use the UDF GUITreeViewEx.au3 of 'Melba23' and I renamed the functions to increase my understanding about the content. I already talked to him about his UDF to respect his rights and intellectual property. I read many forum threads, I tried many ways to get it, but it's seems to be impossible in the way that I use the UDF.

      Question:
      How can I set different item text colors, separately for the TreeView levels?
      How can I set different item background colors, separately for the TreeView levels?

      I found out that _GUICtrlTreeView_AddChild don't let my set this properties directly. But after loading the TreeView content I can't change the items (children) too. Only the font weight to bold I could set with _GUICtrlTreeView_SetBold but I want to do this in a generic way directly at the creation (loading) of the TreeView.

      Of course I tried the different functions to set text color or bkgColor, but it didn't work - maybe I do it wrong.
      I really hope you can help me, give me a hint and understand what I want to do.
      [Solved] final solution made by @LarsJ (see below)

      Thanks for your help - I'm grateful!
      Sven

      CODE
      BEFORE
      AFTER
      ExecutionPlan.zip
×
×
  • Create New...