; www.autoitscript.com/forum/topic/183381-delayed-guictrltreeview-get-index/ ; www.autoitscript.com/forum/topic/100583-treeview-expand-event/ ; www.autoitscript.com/forum/topic/111457-selective-folders-selection/ ; www.autoitscript.com/forum/topic/80327-filebrowser-with-treeview/ ; www.autoitscript.com/forum/topic/144469-solved-dynamic-directory-treeview/ #NoTrayIcon #RequireAdmin #include #include #include #include #Include #Include Opt("WinWaitDelay", 0) Opt("MouseClickDelay", 0) Opt("MouseClickDownDelay", 0) Opt("MouseClickDragDelay", 0) Opt("SendKeyDelay", 0) Opt("SendKeyDownDelay", 0) Opt("WinTitleMatchMode", 3) Opt('GUIOnEventMode', 1) Opt('GUICloseOnEsc' , 1) Global $CheckBoxCount = 0 Global $CheckedItems = '' Global $hGUI = GUICreate("Select files and folders", 530, 400, -1, -1) Global $hTreeView = _GUICtrlTreeView_Create($hGUI, 0, 0, 530, 370, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_CHECKBOXES)) Global $button = GUICtrlCreateButton("Show checked", 0, 370, 90, 30, $SS_Center) GUISetBkColor(0xCECECE) GUICtrlSetOnEvent($button, '_Checked') GUISetOnEvent($GUI_EVENT_CLOSE, '_AllExit') $hImage = _GUIImageList_Create(16, 16, 5, 2) _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 4) _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 54) _GUICtrlTreeView_SetNormalImageList($hTreeView, $hImage) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState(@SW_SHOW, $hGUI) $aDrives = DriveGetDrive('FIXED') If IsArray($aDrives) Then For $i = 1 To $aDrives[0] If DriveStatus($aDrives[$i]) = 'READY' Then $Root = _GUICtrlTreeView_AddChild($hTreeView, '', StringUpper($aDrives[$i]), 0) _GUICtrlTreeView_SetChildren($hTreeView, $Root, True) EndIf Next EndIf $aDrives = DriveGetDrive('REMOVABLE') If IsArray($aDrives) Then For $i = 1 To $aDrives[0] If DriveStatus($aDrives[$i]) = 'READY' Then $Root = _GUICtrlTreeView_AddChild($hTreeView, '', StringUpper($aDrives[$i]), 0) _GUICtrlTreeView_SetChildren($hTreeView, $Root, True) EndIf Next EndIf While 1 Sleep(1000) WEnd Func _AllExit() GUIDelete($hGUI) Exit EndFunc Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hTreeView Switch $iCode Case $NM_CLICK $aPos = GUIGetCursorInfo($hGUI) $ObjectClicked = _GUICtrlTreeView_HitTest($hTreeView, $aPos[0], $aPos[1]) $cItem = _GUICtrlTreeView_HitTestItem($hTreeView, $aPos[0], $aPos[1]) If $ObjectClicked = '16' Then If _GUICtrlTreeView_GetExpanded($hTreeView, $cItem) = True Then ControlTreeView($hGUI, "", $hTreeView, "Collapse", $cItem) Else $sSelectedPath = StringReplace(_GUICtrlTreeView_GetTree($hTreeView, $cItem), "|", "\") If _GUICtrlTreeView_GetChildCount($hTreeView, $cItem) <= 0 Then _SearchFolder($cItem, $sSelectedPath) EndIf EndIf ElseIf $ObjectClicked = '64' Then If _GUICtrlTreeView_GetChecked($hTreeView, $cItem) = False Then ; checked $CheckBoxCount = $CheckBoxCount + 1 $sSelectedPath = StringReplace(_GUICtrlTreeView_GetTree($hTreeView, $cItem), "|", "\") If not StringInStr($sSelectedPath, '\') Then $sSelectedPath = $sSelectedPath & '\' $CheckedItems = $CheckedItems & $sSelectedPath & @CRLF Else ; unchecked $CheckBoxCount = $CheckBoxCount - 1 $sSelectedPath = StringReplace(_GUICtrlTreeView_GetTree($hTreeView, $cItem), "|", "\") If not StringInStr($sSelectedPath, '\') Then $sSelectedPath = $sSelectedPath & '\' $CheckedItems = StringReplace($CheckedItems, $sSelectedPath & @CRLF, '') EndIf EndIf Case $NM_DBLCLK $aPos = GUIGetCursorInfo($hGUI) $ObjectClicked = _GUICtrlTreeView_HitTest($hTreeView, $aPos[0], $aPos[1]) $cItem = _GUICtrlTreeView_HitTestItem($hTreeView, $aPos[0], $aPos[1]) If $ObjectClicked = '2' or $ObjectClicked = '4' Then If _GUICtrlTreeView_GetExpanded($hTreeView, $cItem) = True Then ControlTreeView($hGUI, "", $hTreeView, "Collapse", $cItem) Else $sSelectedPath = StringReplace(_GUICtrlTreeView_GetTree($hTreeView, $cItem), "|", "\") If _GUICtrlTreeView_GetChildCount($hTreeView, $cItem) <= 0 Then _SearchFolder($cItem, $sSelectedPath) EndIf EndIf EndIf Case $TVN_SELCHANGINGA, $TVN_SELCHANGINGW Return 1 Case $NM_SETFOCUS Return 1 EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc Func _SearchFolder($cParent, $sPath) $aFolderList = _FileListToArray($sPath, "*", $FLTA_FOLDERS) If IsArray($aFolderList) Then For $i = 1 To $aFolderList[0] $hItem = _GUICtrlTreeView_AddChild($hTreeView, $cParent, $aFolderList[$i], 0) _GUICtrlTreeView_SetChildren($hTreeView, $hItem, True) Next EndIf $aFileList = _FileListToArray($sPath, "*", $FLTA_FILES) If IsArray($aFileList) Then For $i = 1 To $aFileList[0] _GUICtrlTreeView_AddChild($hTreeView, $cParent, $aFileList[$i], 1, 1) Next EndIf If _GUICtrlTreeView_GetChildCount($hTreeView, $cParent) <= 0 Then _GUICtrlTreeView_SetChildren($hTreeView, $cParent, False) EndIf EndFunc Func _Checked() If $CheckBoxCount = '0' Then MsgBox(0, '', 'Nothing checked.') Return Else $FileList = '' $FolderList = '' $BurnList = StringSplit($CheckedItems, @LF) For $i = 1 to $BurnList[0] - 1 $path = StringStripCR($BurnList[$i]) If StringInStr(FileGetAttrib($path), "D") = 0 Then ; File $FileList = $FileList & $path & @CRLF Else ; Folder $FolderList = $FolderList & $path & @CRLF EndIf Next If $FileList <> '' Then MsgBox(0,'Checked files',$FileList) If $FolderList <> '' Then MsgBox(0,'Checked folders',$FolderList) EndIf EndFunc