Jump to content

Window like explorator with GUICtrlCreateTreeView


tissard
 Share

Recommended Posts

Hello everybody !!!

First, I prefer to prevent everybody i'm french and like all french people my english is very bad !!!!

I've create an application wich allow to get back a spécific path from an INI file and when i click on Search Button i would like display an explorator like in Windows with all the directories and files.

The next step is to select one directory, and copy the directory on several servers at the same place.

So here it's my code, of course the comments are in french sorry:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#Include <String.au3>
#include <File.au3>
#include <Array.au3>
#include <FileListToArray3.au3>
#include <Date.au3>
#Region ### START Koda GUI section ### Form=D:\auto_IT\file_update\copie_folder.kxf
$Form1 = GUICreate("Form1", 813, 653, 1476, 111)
$TreeView1 = GUICtrlCreateTreeView(24, 208, 281, 393, BitOr ($TVS_CHECKBOXES , $TVS_HASBUTTONS , $TVS_HASLINES , $TVS_LINESATROOT, $TVS_SINGLEEXPAND))
$Label1 = GUICtrlCreateLabel("Sélectionnez un dossier à copier vers les différents Serveurs", 16, 168, 287, 17)
$ListAllServer = GUICtrlCreateList("", 328, 208, 137, 396,BitOR($LBS_SORT,$WS_BORDER))
$ListAllServerSelected = GUICtrlCreateList("", 520, 208, 137, 396,BitOR($LBS_SORT,$WS_BORDER))
$Label2 = GUICtrlCreateLabel("Label2", 328, 168, 36, 17)
$Label3 = GUICtrlCreateLabel("Label3", 520, 168, 36, 17)
$BStop = GUICtrlCreateButton("FERMER", 696, 560, 81, 33, $WS_GROUP)
$BSelect = GUICtrlCreateButton(">", 480, 345, 25, 23, $WS_GROUP)
;$BUnSelect = GUICtrlCreateButton("<", 480, 392, 25, 25, $WS_GROUP)
;$BSelectAll = GUICtrlCreateButton(">>", 480, 296, 25, 25, $WS_GROUP)
$BUnSelectAll = GUICtrlCreateButton("<<", 480, 392, 25, 25, $WS_GROUP)
$BStart = GUICtrlCreateButton("DEMARRER", 696, 336, 81, 41, $WS_GROUP)
$Input1 = GUICtrlCreateInput("", 184, 88, 249, 21)
$Label4 = GUICtrlCreateLabel("Chemin de recherche", 8, 88, 155, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$Group1 = GUICtrlCreateGroup("", 0, 120, 785, 9)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$BSearch = GUICtrlCreateButton("Rechercher", 440, 88, 73, 25, $WS_GROUP)
$Label5 = GUICtrlCreateLabel("Copie automatique de Dossiers et fichiers ", 24, 8, 546, 36)
GUICtrlSetFont(-1, 20, 400, 0, "ITC Avant Garde Gothic")

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


GLOBAL $deb_chemin = "\\"                   ; Début du chemin vers partage du serveur
GLOBAL $config_file = "config_copy2.ini"        ; Fichier de paramétrage de l'application
GLOBAL $path_log                            ; Création d'un fichier LOG temporaire / Penser à le supprimer à la fin de l'exécution du l'application
GLOBAL $default_path                        ; Création d'un fichier LOG temporaire / Penser à le supprimer à la fin de l'exécution du l'application
GLOBAL $OS_version = @OSVersion
GLOBAL $order_sequence = 0
;
;
;   RECUPERATION DES INFORMATION CONTENU DANS LE FICHIER DE PARAMETRAGE
;
;
$default_path = IniRead($config_file,"PATH","path","NotFound")
If @error Then
    MsgBox(4096, "LOG", "Error occurred, probably no INI file.")
Else
    GUICtrlSetData($Input1,$default_path)
EndIf
$path_log = IniRead($config_file,"LOG","log","NotFound")
If @error Then
    MsgBox(4096, "LOG", "Error occurred, probably no INI file.")
EndIf
$var_liste = IniReadSection($config_file,"LISTE")
If @error Then
    MsgBox(4096, "LISTE", "Error occurred, probably no INI file.")
EndIf
Dim $liste_serveur[UBound($var_liste)-1]                ; Liste des serveurs CPAM
Dim $liste_etat_serveur[UBound($var_liste)-1]           ; Liste des état des serveurs CPAM
Dim $liste_ip_serveur[UBound($var_liste)-1]             ; Liste des IP des serveurs CPAM
Dim $text[UBound($var_liste)-1]

$j=0
For $i = 1 To $var_liste[0][0]
    $array_serveur = StringSplit($var_liste[$i][1],"|",1)
    If @error Then
        MsgBox(4096, "StringSplit Error", "Error occurred, probably no data in $var_liste.")
    EndIf
    $liste_serveur[$j] = $array_serveur[1]
    $liste_ip_serveur[$j] = $array_serveur[2]
    GUICtrlSetData($ListAllServer,$liste_serveur[$j])
    $j = $j +1
Next

;$line = _ArrayToString($text,@CRLF,0,UBound($liste_ip_serveur) -1)
;GUICtrlSetData($ListAllServer,$line)
;If @error Then
;   MsgBox(4096, "GUICtrlSetData Error", "Error occurred for 'GUICtrlSetData' function.")
;Else
;   $order_sequence =1
;EndIf

;For $i = 1 To $var_type[0][0]
;   $ar_Array = _FileListToArray3 ($deb_chemin&$serveur&$work_folder, "*."&$var_type[$i][1], 1, 1, 1,"Temp|TMP")
;   $ar_Array = _FileListToArrayRecAll1($sPathF, ByRef $sFileStringF, $sFilterF, $sExcludeF = "")
;   $size_ar_Array = $size_ar_Array + UBound($ar_Array)-1
;Next
$msg = 0
While $msg <> $GUI_EVENT_CLOSE
    $msg = GUIGetMsg()

    Select

        Case $msg = $BSearch


        Case $msg = $BStart

        Case $msg = $BSelect
            $vSelect = GUICtrlRead($ListAllServer,$GUI_CHECKED)
            GUICtrlSetData($ListAllServerSelected,$vSelect)

        Case $msg = $BUnSelectAll
            $vUnSelect = GUICtrlRead($ListAllServerSelected,$GUI_CHECKED)
            GUICtrlSetData($ListAllServerSelected,"")

        Case $msg = $BStop
            Exit
    EndSelect
WEnd


;****************************************************************************************
;
;   Fonction permettant de vérifier si le serveur passé en paramètre est en ligne
;   -   Entrée : serveur
;   -   Sortie : etat du serveur
;
Func onlineserver($ip_serveur)

    ; Vérification du type d'OS et exécution de la commande PING en fonction de celui ci
    ; La commande PING renvoi le résultat vers un fichier log
    If $OS_version = "WIN_XP" Then
        Sleep(250)
        RunWait(@COMSPEC & " /c C:\WINDOWS\system32\ping.exe -w 1 -n 1 "& $ip_serveur & ">" & $path_log,"",@SW_HIDE)
        If @error Then
            MsgBox(4096, "RunWait Error", "Error occurred with PING command for XP.")
        EndIf
    Else
        Sleep(250)
        RunWait(@COMSPEC & " /c C:\WINNT\system32\ping.exe -w 1 -n 1 "& $ip_serveur & ">" & $path_log)
        If @error Then
            MsgBox(4096, "RunWait Error", "Error occurred with PING command for Other OS.")
        EndIf
    EndIf
    if Not @error Then
        ; Lecture du fichier LOG
        $read = FileRead($path_log)
        ; Découpage du fichier LOG
        $line = StringSplit($read, @CR)
        ; Pour chaque ligne du fichier
        For $j = 1 To $line[0]
            $var = FileReadLine($path_log, $j)
            ; Comparaison entre la ligne récupérée dans fichier "$var " et "perdus = 0 (perte 0%)"
            If StringInStr($var,"perdus = 0 (perte 0%)") Then
                $etat_serveur = 1 ; valeur de retour à 1 => Serveur en ligne
                ExitLoop
            ElseIf StringInStr($var,"perdus = 1 (perte 100%)") Then
                $etat_serveur = 0 ; valeur de retour à 1 => Serveur en ligne
            ExitLoop
            EndIf
        Next
    Elseif @error Then
        $etat_serveur = 0 ; valeur de retour à 0 => Serveur en Hors ligne
    EndIf
    Return $etat_serveur
EndFunc

Thanks a lot for your help and see you soon !!!

Edited by tissard
Link to comment
Share on other sites

  • Moderators

tissard,

Bienvenu au forum AutoIt. :idea:

Kafu has already produced something to do what you want here.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Hello !!!!

It's wonderfull !!!!

I've download the ShellTristateTreeView_v27.zip from the link and i've modify my code.

It's work well !!

Only one think, when i want to get back the result of an array like in the sample, it doesn't work.

I don't understand what appened.

I know the problem come from the function "Func __func_LocationTree_ReturnState()" but ....

This is my new code:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#Include <String.au3>
#include <File.au3>
#include <Array.au3>
#include <FileListToArray3.au3>
#include <Date.au3>
#include <GuiTreeView.au3>
#include <GuiImageList.au3>

Global $aTreeViewItemState[1][1], $aTreeViewItemStateChecked[1][1], $aFolders_Scanned_in_last_Run
Global $c_Checkbox_SearchFor_Recursive
Global $sStateIconFile = "checkbox_modern.bmp"
#include<ShellTristateTreeView_v27.au3>
GLOBAL $config_file = @ScriptDir & "\config_copy2.ini"  ; Fichier de paramétrage de l'application
GLOBAL $path_log            ; Création d'un fichier LOG temporaire / Penser à le supprimer à la fin de l'exécution du l'application
GLOBAL $default_path        ; Création d'un fichier LOG temporaire / Penser à le supprimer à la fin de l'exécution du l'application
GLOBAL $OS_version = @OSVersion
GLOBAL $order_sequence = 0
Global $aTreeViewItemState[1][1], $aTreeViewItemStateChecked[1][1], $aFolders_Scanned_in_last_Run
Global $c_Checkbox_SearchFor_Recursive
Global $sStateIconFile = "checkbox_modern.bmp"

#Region ### START Koda GUI section ### Form=D:\auto_IT\file_update\copie_folder.kxf
$FormCOPY = GUICreate("Application de copie de dossiers vers Serveurs", 813, 653, 1476, 111)
$Label5 = GUICtrlCreateLabel("Copie automatique de Dossiers et fichiers ", 24, 50, 546, 36)
GUICtrlSetFont(-1, 20, 400, 0, "ITC Avant Garde Gothic")

$c_TreeView_LocationFilter = _GUICtrlTreeView_Create($FormCOPY,24, 208, 281, 393,  BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_CHECKBOXES), $WS_EX_CLIENTEDGE)
GUIRegisterMsg($WM_NOTIFY, "MY_WM_NOTIFY_ShellTristateTreeView")
$Label1 = GUICtrlCreateLabel("Sélectionnez un dossier à copier"[email="&@LF"]&@LF[/email]&" vers les différents Serveurs", 16, 168, 287, 40)
$ListAllServer = GUICtrlCreateList("", 328, 208, 137, 396,BitOR($LBS_SORT,$WS_BORDER))
$ListAllServerSelected = GUICtrlCreateList("", 520, 208, 137, 396,BitOR($LBS_SORT,$WS_BORDER))
$Label2 = GUICtrlCreateLabel("Liste des serveurs "[email="&@LF&"]&@LF&"sélectionnés[/email]", 520, 168, 100, 40)
$BStop = GUICtrlCreateButton("FERMER", 696, 560, 81, 33 ,0)
$BSelect = GUICtrlCreateButton(">", 480, 345, 25, 23,0 )
$BUnSelectAll = GUICtrlCreateButton("<<", 480, 392, 25, 25,0)
$BStart = GUICtrlCreateButton("DEMARRER", 696, 336, 81, 41, 0 )
GUICtrlSetOnEvent($BStart, "__func_LocationTree_ReturnState")
GUIRegisterMsg($WM_NOTIFY, "MY_WM_NOTIFY_ShellTristateTreeView")
__func_LocationTree_Create_Do()
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

;
;
; RECUPERATION DES INFORMATION CONTENU DANS LE FICHIER DE PARAMETRAGE
;
;

$path_log = IniRead($config_file,"LOG","log","NotFound")
If @error Then
MsgBox(4096, "LOG", "Error occurred, probably no INI file.")
Exit
EndIf
$var_liste = IniReadSection($config_file,"LISTE")
If @error Then
MsgBox(4096, "LISTE", "Error occurred, probably no INI file.")
Exit
EndIf
Dim $liste_serveur[UBound($var_liste)-1]    ; Liste des serveurs CPAM
Dim $liste_etat_serveur[UBound($var_liste)-1]   ; Liste des état des serveurs CPAM
Dim $liste_ip_serveur[UBound($var_liste)-1]    ; Liste des IP des serveurs CPAM
Dim $text[UBound($var_liste)-1]

$j=0
For $i = 1 To $var_liste[0][0]
$array_serveur = StringSplit($var_liste[$i][1],"|",1)
If @error Then
  MsgBox(4096, "StringSplit Error", "Error occurred, probably no data in $var_liste.")
EndIf
$liste_serveur[$j] = $array_serveur[1]
$liste_ip_serveur[$j] = $array_serveur[2]
GUICtrlSetData($ListAllServer,$liste_serveur[$j])
$j = $j +1
Next



$msg = 0
While $msg <> $GUI_EVENT_CLOSE
$msg = GUIGetMsg()

Select
  ;Case $msg = $BSearch
  Case $msg = $BStart

  Case $msg = $BSelect
   $vSelect = GUICtrlRead($ListAllServer,$GUI_CHECKED)
   GUICtrlSetData($ListAllServerSelected,$vSelect)

  Case $msg = $BUnSelectAll
   $vUnSelect = GUICtrlRead($ListAllServerSelected,$GUI_CHECKED)
   GUICtrlSetData($ListAllServerSelected,"")

  Case $msg = $BStop
   Exit
EndSelect
WEnd


;****************************************************************************************
;
; Fonction permettant de vérifier si le serveur passé en paramètre est en ligne
; - Entrée : serveur
; -  Sortie : etat du serveur
;
Func onlineserver($ip_serveur)

; Vérification du type d'OS et exécution de la commande PING en fonction de celui ci
; La commande PING renvoi le résultat vers un fichier log
If $OS_version = "WIN_XP" Then
  Sleep(250)
  RunWait(@COMSPEC & " /c C:\WINDOWS\system32\ping.exe -w 1 -n 1 "& $ip_serveur & ">" & $path_log,"",@SW_HIDE)
  If @error Then
   MsgBox(4096, "RunWait Error", "Error occurred with PING command for XP.")
  EndIf
Else
  Sleep(250)
  RunWait(@COMSPEC & " /c C:\WINNT\system32\ping.exe -w 1 -n 1 "& $ip_serveur & ">" & $path_log)
  If @error Then
   MsgBox(4096, "RunWait Error", "Error occurred with PING command for Other OS.")
  EndIf
EndIf
if Not @error Then
  ; Lecture du fichier LOG
  $read = FileRead($path_log)
  ; Découpage du fichier LOG
  $line = StringSplit($read, @CR)
  ; Pour chaque ligne du fichier
  For $j = 1 To $line[0]
   $var = FileReadLine($path_log, $j)
   ; Comparaison entre la ligne récupérée dans fichier "$var " et "perdus = 0 (perte 0%)"
   If StringInStr($var,"perdus = 0 (perte 0%)") Then
    $etat_serveur = 1 ; valeur de retour à 1 => Serveur en ligne
    ExitLoop
   ElseIf StringInStr($var,"perdus = 1 (perte 100%)") Then
    $etat_serveur = 0 ; valeur de retour à 1 => Serveur en ligne
   ExitLoop
   EndIf
  Next
Elseif @error Then
  $etat_serveur = 0 ; valeur de retour à 0 => Serveur en Hors ligne
EndIf
Return $etat_serveur
EndFunc




Func __func_LocationTree_ReturnState()

$aTreeViewItemState = ""
Dim $aTreeViewItemState[_GUICtrlTreeView_GetCount($c_TreeView_LocationFilter)][2]
$hItemRoot = _GUICtrlTreeView_GetFirstItem($c_TreeView_LocationFilter)
$aTreeViewItemState[0][0] = "My Computer (" & @ComputerName & ")"
$aTreeViewItemState[0][1] = MyCtrlGetItemState($c_TreeView_LocationFilter, $hItemRoot)
$iCountStateChecked = 1
If MyCtrlGetItemState($c_TreeView_LocationFilter, $hItemRoot) = 1 Then ; if "My Computer" is activated
  $hItemSub = _GUICtrlTreeView_GetFirstChild($c_TreeView_LocationFilter, $hItemRoot)
  While $hItemSub
   $iCountStateChecked += 1
   $sText = _GUICtrlTreeView_GetText($c_TreeView_LocationFilter, $hItemSub)
   $aTreeViewItemState[$iCountStateChecked][0] = _ShellTreeView_GetSelected($c_TreeView_LocationFilter, $sText, $hItemSub, True)
   $aTreeViewItemState[$iCountStateChecked][1] = MyCtrlGetItemState($c_TreeView_LocationFilter, $hItemSub)
   $hItemSub = _GUICtrlTreeView_GetNextChild($c_TreeView_LocationFilter, $hItemSub)
  WEnd
ElseIf MyCtrlGetItemState($c_TreeView_LocationFilter, $hItemRoot) = 2 Then ; if anything else is activated
  _TreeviewGetChildState($c_TreeView_LocationFilter, $hItemRoot, $iCountStateChecked)
EndIf

; Parse and clean the results, just keep top-most parent directories activated and skip childs
_ArrayDelete($aTreeViewItemState, 0)
_ArraySort($aTreeViewItemState, 1)
For $iCountStateChecked = UBound($aTreeViewItemState) - 1 To 1 Step -1
  If StringLen($aTreeViewItemState[$iCountStateChecked][0]) = 0 Then _ArrayDelete($aTreeViewItemState, $iCountStateChecked)
Next
_ArraySort($aTreeViewItemState)
For $i = 0 To UBound($aTreeViewItemState) - 2
  If $i = UBound($aTreeViewItemState) - 1 Then ExitLoop
  If StringInStr($aTreeViewItemState[$i + 1][0], $aTreeViewItemState[$i][0]) Then
   _ArrayDelete($aTreeViewItemState, $i + 1)
   $i = $i - 1
  EndIf
Next
If StringLen($aTreeViewItemState[0][0]) = 0 Then
  MsgBox(270400, "Error", "No Location selected..." & @CRLF & @CRLF & "You have to select at least one location to search.")
Else

  IniWrite($config_file, "Settings", "Folders_Scanned_in_last_Run", "")
  For $i = 0 To UBound($aTreeViewItemState) - 1 ; loop through selected folders
   If FileExists($aTreeViewItemState[$i][0]) = 1 Then
    IniWrite($config_file, "Settings", "Folders_Scanned_in_last_Run", $aTreeViewItemState[$i][0] & "|" & IniRead($config_file, "Settings", "Folders_Scanned_in_last_Run", ""))
   EndIf
  Next

  _ArrayDisplay($aTreeViewItemState)

EndIf
EndFunc   ;==>__func_LocationTree_ReturnState
; =======================
; Create Treeview
; =======================
Func __func_LocationTree_Create($b_AddNetworkDrives)

_GUICtrlTreeView_DeleteAll($c_TreeView_LocationFilter)
_GUICtrlTreeView_BeginUpdate($c_TreeView_LocationFilter)
_ShellTreeView_Create($c_TreeView_LocationFilter, $b_AddNetworkDrives) ; AddNetworkDrives Default = true (always)
_GUICtrlTreeView_SetState($c_TreeView_LocationFilter, _GUICtrlTreeView_GetFirstItem($c_TreeView_LocationFilter), $TVIS_EXPANDED, True) ; expand First level (show drives)
_ShellTreeView_GetSelected($c_TreeView_LocationFilter, _GUICtrlTreeView_GetText($c_TreeView_LocationFilter, _GUICtrlTreeView_GetFirstItem($c_TreeView_LocationFilter)), _GUICtrlTreeView_GetFirstItem($c_TreeView_LocationFilter))

Global $aFolders_Scanned_in_last_Run = StringSplit(IniRead($config_file, "Settings", "Folders_Scanned_in_last_Run", ""), "|")
_ArrayDelete($aFolders_Scanned_in_last_Run, UBound($aFolders_Scanned_in_last_Run) - 1)
$aFolders_Scanned_in_last_Run[0] = UBound($aFolders_Scanned_in_last_Run) - 1
If $aFolders_Scanned_in_last_Run[0] > 0 Then
  For $i = 1 To $aFolders_Scanned_in_last_Run[0]
   If UBound($aFolders_Scanned_in_last_Run) = $i Then ExitLoop
   If Not StringInStr(FileGetAttrib($aFolders_Scanned_in_last_Run[$i]), 'D') Then
    _ArrayDelete($aFolders_Scanned_in_last_Run, $i)
    $aFolders_Scanned_in_last_Run[0] = UBound($aFolders_Scanned_in_last_Run) - 1
    $i -= 1
   EndIf
  Next
EndIf
$aFolders_Scanned_in_last_Run[0] = UBound($aFolders_Scanned_in_last_Run) - 1

If $aFolders_Scanned_in_last_Run[0] > 0 Then
  __func_LocationTree_CheckOldValues()
  _GUICtrlTreeView_Expand($c_TreeView_LocationFilter, _GUICtrlTreeView_GetFirstItem($c_TreeView_LocationFilter), False) ; collapse back to root
  _GUICtrlTreeView_SetState($c_TreeView_LocationFilter, _GUICtrlTreeView_GetFirstItem($c_TreeView_LocationFilter), $TVIS_EXPANDED, True) ; expand First level (show drives)
EndIf

_GUICtrlTreeView_EndUpdate($c_TreeView_LocationFilter)
LoadStateImage($c_TreeView_LocationFilter, $sStateIconFile)

_GUICtrlTreeView_SetUnicodeFormat($c_TreeView_LocationFilter)

EndFunc   ;==>__func_LocationTree_Create

Func __func_LocationTree_Create_Do()
;If GUICtrlRead($c_Checkbox_AddNetworkDrives_Always) = $GUI_CHECKED Then
  __func_LocationTree_Create(True)
;Else
; __func_LocationTree_Create(False)
;EndIf
EndFunc   ;==>__func_LocationTree_Create_Do

Func __func_LocationTree_CheckOldValues($hItemRoot = '')
If $hItemRoot = '' Then $hItemRoot = _GUICtrlTreeView_GetFirstItem($c_TreeView_LocationFilter)
; ConsoleWrite('__func_LocationTree_CheckOldValues ' & $hItemRoot & @CRLF)
$hItemSub = _GUICtrlTreeView_GetFirstChild($c_TreeView_LocationFilter, $hItemRoot)

While $hItemSub
  If $aFolders_Scanned_in_last_Run[0] = 0 Then Return
  $sText = _GUICtrlTreeView_GetText($c_TreeView_LocationFilter, $hItemSub)
  $sDirPointer = _ShellTreeView_GetSelected($c_TreeView_LocationFilter, $sText, $hItemSub, True)
  If FileExists($sDirPointer) Then
   For $i = 1 To $aFolders_Scanned_in_last_Run[0]
    If $sDirPointer = $aFolders_Scanned_in_last_Run[$i] Then
    ; check item
    ; ConsoleWrite("Check " & $sDirPointer & @CRLF)
    MyCtrlSetItemState($c_TreeView_LocationFilter, $hItemSub, $GUI_CHECKED)
    _ArrayDelete($aFolders_Scanned_in_last_Run, $i)
    $aFolders_Scanned_in_last_Run[0] -= 1
    ElseIf StringInStr($aFolders_Scanned_in_last_Run[$i], $sDirPointer) Then
    ; expand
    ; recurse function
    ; ConsoleWrite("Expand " & $sDirPointer & @CRLF)
    If _GUICtrlTreeView_GetExpanded($c_TreeView_LocationFilter, $hItemSub) = False Then
      ;ConsoleWrite(_GUICtrlTreeView_GetText($hWndFrom, $hControl) & @CRLF)
      _ShellTreeView_GetSelected($c_TreeView_LocationFilter, _GUICtrlTreeView_GetText($c_TreeView_LocationFilter, $hItemSub), $hItemSub, False, False)
    EndIf
    _GUICtrlTreeView_SetState($c_TreeView_LocationFilter, $hItemSub, $TVIS_EXPANDED, True)
    __func_LocationTree_CheckOldValues($hItemSub)
    EndIf
   Next
  EndIf
  $hItemSub = _GUICtrlTreeView_GetNextChild($c_TreeView_LocationFilter, $hItemSub)
WEnd
EndFunc   ;==>__func_LocationTree_CheckOldValues


; #FUNCTION# ==================================================================================================
; Name............: MY_WM_NOTIFY
; Description.....: Add TreeView items with directorys structures
;   Handle Windows Message notifications
;   Merge of the two MY_WM_NOTIFY functions from
;   ShellTreeView.au3 and TristateTreeViewLib.au3
;   Please don't ask me about the magic being done here in detail : )
;
;   Though I'm quiet sure the function needs consolidation....
;
; ====================================================================================================

Func MY_WM_NOTIFY_ShellTristateTreeView($hWnd, $Msg, $wParam, $lParam)

;ShellTreeView.au3
; ==========
Local $tNMHDR, $hWndFrom, $iCode
$tNMHDR = DllStructCreate($tagNMHDR, $lParam)
$hWndFrom = DllStructGetData($tNMHDR, "hWndFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
  Case $hWndTreeView
   ;ConsoleWrite($iCode & @CRLF)
   Switch $iCode
    Case - 454 ; $TVN_ITEMEXPANDING (-405) > Changed due to TreeView UNICODE to -454!!!!?
    ;Case $TVN_ITEMEXPANDING
    ;ConsoleWrite($TVN_ITEMEXPANDING & @CRLF)
    Local $tINFO = DllStructCreate($tagNMTREEVIEW, $lParam)
    Local $hControl = DllStructGetData($tINFO, "NewhItem")
    If _GUICtrlTreeView_GetExpanded($hWndTreeView, $hControl) = False Then
      ;ConsoleWrite(_GUICtrlTreeView_GetText($hWndFrom, $hControl) & @CRLF)
      _ShellTreeView_GetSelected($hWndFrom, _GUICtrlTreeView_GetText($hWndFrom, $hControl), $hControl, False, False)
    EndIf
   EndSwitch
EndSwitch

;TristateTreeViewLib.au3
; ==========
Local $stNmhdr = DllStructCreate("dword;int;int", $lParam)
Local $hWndFrom = DllStructGetData($stNmhdr, 1)
Local $nNotifyCode = DllStructGetData($stNmhdr, 3)
Local $hItem = 0
; Check if its treeview and only NM_CLICK and TVN_KEYDOWN
If Not BitAND(GetWindowLong($hWndFrom, $GWL_STYLE), $TVS_CHECKBOXES) Or _
   Not ($nNotifyCode = $NM_CLICK Or $nNotifyCode = $TVN_KEYDOWN) Then Return $GUI_RUNDEFMSG

If $nNotifyCode = $TVN_KEYDOWN Then
  Local $lpNMTVKEYDOWN = DllStructCreate("dword;int;int;short;uint", $lParam)

  ; Check for 'SPACE'-press
  If DllStructGetData($lpNMTVKEYDOWN, 4) <> $VK_SPACE Then Return $GUI_RUNDEFMSG
  $hItem = SendMessage($hWndFrom, $TVM_GETNEXTITEM, $TVGN_CARET, 0)
Else
  Local $Point = DllStructCreate("int;int")

  GetCursorPos($Point)
  ScreenToClient($hWndFrom, $Point)

  ; Check if clicked on state icon
  Local $tvHit = DllStructCreate("int[2];uint;dword")
  DllStructSetData($tvHit, 1, DllStructGetData($Point, 1), 1)
  DllStructSetData($tvHit, 1, DllStructGetData($Point, 2), 2)

  $hItem = SendMessage($hWndFrom, $TVM_HITTEST, 0, DllStructGetPtr($tvHit))

  If Not BitAND(DllStructGetData($tvHit, 2), $TVHT_ONITEMSTATEICON) Then Return $GUI_RUNDEFMSG
EndIf

If $hItem > 0 Then

  Local $nState = GetItemState($hWndFrom, $hItem)

  $bCheckItems = 1

  If $nState = 2 Then
   $nState = 0
  ElseIf $nState = 3 Then
   $nState = 1
  ElseIf $nState > 3 Then
   $nState = $nState - 1
   $bCheckItems = 0
  EndIf

  SetItemState($hWndFrom, $hItem, $nState)

  $nState += 1

  ; If item are disabled there is no chance to change it and it's parents/children
  If $bCheckItems Then
   CheckParents($hWndFrom, $hItem, $nState)
   CheckChildItems($hWndFrom, $hItem, $nState)
  EndIf
EndIf

Return $GUI_RUNDEFMSG
EndFunc   ;==>MY_WM_NOTIFY_ShellTristateTreeView

This is my INI file :

[Settings]
Checkbox_SearchFor_Recursive=1
Checkbox_AddNetworkDrives_Always=1
[LOG]
log=c:\tmp_file.log
[LISTE]
serveur=XF01|192.168.1.100
serveur=XF02|192.168.1.101
serveur=XF03|192.168.1.102
serveur=XF04|192.168.1.103

If someone have an idear ????

See you soon

Edited by tissard
Link to comment
Share on other sites

  • Moderators

tissard,

You are mixing OnEvent mode and GetMessage mode - you must use one or the other. :idea:

You intially set your button to have an event associated with it:

$BStart = GUICtrlCreateButton("DEMARRER", 696, 336, 81, 41, 0 )
GUICtrlSetOnEvent($BStart, "__func_LocationTree_ReturnState")

but you have not set OnEvent mode (which you do by using Opt("GUIOnEventMode", 1)) so that it has no effect.

And then in your GUIGetMsg loop you have no code to action when the button is pressed: :)

$msg = GUIGetMsg()

Select
     ;Case $msg = $BSearch
     Case $msg = $BStart

    Case $msg = $BSelect

Change it to read like this:

$msg = GUIGetMsg()

Select
    ;Case $msg = $BSearch
    Case $msg = $BStart
        "__func_LocationTree_ReturnState
    Case $msg = $BSelect

And it should work - or at least the function will run! :(

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

You have totaly reason.!!!!

In fact, just after i've wrote the topic, i've found the same solution but i haven't the time to write it on the forum.Posted Image

So It's work !!!!

Thanks a lot for your help !!!!!!Posted Image

Link to comment
Share on other sites

  • 2 weeks later...

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...