;-------------------------------------------------------------------- ;Includes ;-------------------------------------------------------------------- #include #include #include #include #include #Include #include-once ;-------------------------------------------------------------------- ;Declarations ;-------------------------------------------------------------------- Global $hImage, $hWndTreeView, $objFSO, $hCommonDocs, $hMyDocs Global $hSelect,$hSelect2,$hSelect2,$hSelect2_2,$file,$sText2,$hSelect3,$hSelect3_2 ;-------------------------------------------------------------------- ;Declarations pour l'UDF ;-------------------------------------------------------------------- $objFSO = ObjCreate("Scripting.FileSystemObject") $hImage = _GUIImageList_Create(16, 16, 5, 3) _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 15) _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 6) _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 8) _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 3) _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 7) _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 4) _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 11) ;-------------------------------------------------------------------- ;Koda ;-------------------------------------------------------------------- #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("By Tim v2.1", @DesktopWidth /1.5 + 200, @Desktopheight /1.5 +100, @DesktopWidth /6 - 100 , @Desktopheight /16) $hTreeView = _GUICtrlTreeView_Create($Form1,610, 48, 260, 550,BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT), _ $WS_EX_CLIENTEDGE) $hTreeView2 = _GUICtrlTreeView_Create($Form1,405, 48, 200, 550) $generalitem = _GUICtrlTreeView_Add($hTreeView2,0, "Scripts") _ShellTreeView_Create($hTreeView) $Edit1 = GUICtrlCreateEdit("", 24, 48, 377, 550) GUICtrlSetData(-1, "") ;$Button1 = GUICtrlCreateButton("Voir le script séléctionné", 432, 8, 161, 33, 0) $Button2 = GUICtrlCreateButton("Executer le script visionné", 48, 8, 321, 33, 0) #EndRegion ### END Koda GUI section ### GUISetState(@SW_SHOW) ;-------------------------------------------------------------------- ;Affichage de la gui, debut du script ;-------------------------------------------------------------------- While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit; Fonction pour quitter... Mais honnetement, qui voudrait fermer un programme comme ca? Case $Button2 $hSelect3 = _GUICtrlTreeView_GetSelection($hTreeView2) If $hSelect3 and $hSelect3 <> $hSelect3_2 Then $sText2 = _GUICtrlTreeView_GetText($hTreeView2, $hSelect3) ShellExecute($file & $sText2) EndIf $hSelect3_2 = $hSelect3 EndSwitch $hSelect2 = _GUICtrlTreeView_GetSelection($hTreeView2) If $hSelect2 and $hSelect2 <> $hSelect2_2 Then $sText2 = _GUICtrlTreeView_GetText($hTreeView2, $hSelect2) GUICtrlSetData($Edit1,Fileread($file & $sText2)) EndIf $hSelect2_2 = $hSelect2 $hSelect = _GUICtrlTreeView_GetSelection($hTreeView) If $hSelect and $hSelect <> $hSelect_2 Then $sText = _GUICtrlTreeView_GetText($hTreeView, $hSelect) $file = _ShellTreeView_GetSelected($hTreeView, $sText, $hSelect) _Get_scripts() EndIf $hSelect_2 = $hSelect Sleep(50); now, on dort pour ne pas faire trop mal au processeur WEnd ;-------------------------------------------------------------------- ;Fonction _get_scripts par Timothée, c'est elle qui va gerer l'affichage du 2eme treeview ;-------------------------------------------------------------------- Func _Get_scripts() _GUICtrlTreeView_SetText($hTreeView2, $generalitem,$file) _GUICtrlTreeView_DeleteChildren($hTreeView2, $generalitem) ; Shows the filenames of all files in the current directory. FileChangeDir($file) $search = FileFindFirstFile("*.vbs") $search2 = FileFindFirstFile("*.bat") $search3 = FileFindFirstFile("*.au3") ; Check if the search was successful While $search <> -1 $file = FileFindNextFile($search) If @error Then ExitLoop _GUICtrlTreeView_AddChild($hTreeView2, $generalitem, $file) WEnd While $search2 <> -1 $file = FileFindNextFile($search2) If @error Then ExitLoop _GUICtrlTreeView_AddChild($hTreeView2, $generalitem, $file) WEnd While $search3 <> -1 $file = FileFindNextFile($search3) If @error Then ExitLoop _GUICtrlTreeView_AddChild($hTreeView2, $generalitem, $file) WEnd ; Close the search handle FileClose($search) FileClose($search2) FileClose($search3) _GUICtrlTreeView_Expand($hTreeView2) Endfunc ;-------------------------------------------------------------------- ;//////////////////////////////////////////////////////////////////// ;-------------------------------------------------------------------- ; Utilisation d'un UDF Anglais //////////////////////////////////// ;-------------------------------------------------------------------- ;//////////////////////////////////////////////////////////////////// ;-------------------------------------------------------------------- ; #FUNCTION# ================================================================================================== ; Name............: _ShellTreeView_Create ; Description.....: Add TreeView items with drives structures ; Syntax..........: _ShellTreeView_Create($hTreeView) ; Parameter(s)....: $hTreeView - Handle to the TreeView control ; Return value(s).: None ; Note(s).........: Tested on AutoIt 3.2.12.1 and Windows XP SP2 ; Author(s).......: R.Gilman (a.k.a. rasim) ; ============================================================================================================== Func _ShellTreeView_Create($hTreeView) Local $RootItem, $aDrives, $hChild, $i $hWndTreeView = $hTreeView GUIRegisterMsg($WM_NOTIFY, "_TVN_ITEMEXPANDING") _GUICtrlTreeView_SetNormalImageList($hWndTreeView, $hImage) $RootItem = _GUICtrlTreeView_Add($hWndTreeView, 0, "My computer", 0, 0) $aDrives = DriveGetDrive("ALL") For $i = 1 To $aDrives[0] $aDrives[$i] = StringUpper($aDrives[$i]) Next For $i = 1 To $aDrives[0] Switch DriveGetType($aDrives[$i]) Case "Removable" If ($aDrives[$i] = "a:") Or ($aDrives[$i] = "b:") Then $hChild = _GUICtrlTreeView_AddChild($hWndTreeView, $RootItem, $aDrives[$i], 1, 1) ;_ShellTreeView_GetSelected($aDrives[$i], $hChild) Else _GUICtrlTreeView_AddChild($hWndTreeView, $RootItem, $aDrives[$i], 4, 4) EndIf Case "Fixed" $hChild = _GUICtrlTreeView_AddChild($hWndTreeView, $RootItem, $aDrives[$i], 2, 2) _ShellTreeView_GetSelected($hWndTreeView, $aDrives[$i], $hChild) Case "CDROM" $hChild = _GUICtrlTreeView_AddChild($hWndTreeView, $RootItem, $aDrives[$i], 6, 6) _ShellTreeView_GetSelected($hWndTreeView, $aDrives[$i], $hChild) EndSwitch Next $hCommonDocs = _GUICtrlTreeView_AddChild($hWndTreeView, $RootItem, StringRegExpReplace(@DocumentsCommonDir, "^.*\\", ""), 3, 5) _ShellTreeView_GetSelected($hWndTreeView, @DocumentsCommonDir, $hCommonDocs) $hMyDocs = _GUICtrlTreeView_AddChild($hWndTreeView, $RootItem, StringRegExpReplace(@MyDocumentsDir, "^.*\\", ""), 3, 5) _ShellTreeView_GetSelected($hWndTreeView, @MyDocumentsDir, $hMyDocs) EndFunc ;==>_ShellTreeView_Create Func _TVN_ITEMEXPANDING($hWnd, $Msg, $wParam, $lParam) Local $tNMHDR, $hWndFrom, $iCode $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndTreeView Switch $iCode Case $TVN_ITEMEXPANDING Local $tINFO = DllStructCreate($tagNMTREEVIEW, $lParam) Local $hControl = DllStructGetData($tINFO, "NewhItem") If _GUICtrlTreeView_GetExpanded($hWndTreeView, $hControl) = False Then _ShellTreeView_GetSelected($hWndFrom, _GUICtrlTreeView_GetText($hWndFrom, $hControl), $hControl) EndIf EndSwitch EndSwitch Return "GUI_RUNDEFMSG" EndFunc ;==>_TVN_ITEMEXPANDING ; #FUNCTION# ================================================================================================== ; Name............: _ShellTreeView_GetSelected ; Description.....: Add TreeView items with directorys structures ; Syntax..........: _ShellTreeView_GetSelected($hWndTreeView, $sDrive, $hControl) ; Parameter(s)....: $hTreeView - Handle to the TreeView control ; $sDrive - String contains drive letter or text of selected TreeView item ; $hControl - Child handle ; Return value(s).: A full path to a selected directory ; Note(s).........: Tested on AutoIt 3.2.12.1 and Windows XP SP2 ; Author(s).......: R.Gilman (a.k.a. rasim) ; ============================================================================================================== Func _ShellTreeView_GetSelected($hWndTreeView, $sDrive, $hControl) Switch _IsDocDir($sDrive, $hControl) Case 1 $sDrive = @DocumentsCommonDir Case 2 $sDrive = @MyDocumentsDir EndSwitch If Not FileExists($sDrive) Then Local $hParent = _GUICtrlTreeView_GetParentHandle($hWndTreeView, $hControl), $iFullPath If _GUICtrlTreeView_GetText($hWndTreeView, $hParent) = StringRegExpReplace(@DocumentsCommonDir, "^.*\\", "") Then $iFullPath = @DocumentsCommonDir & "\" & $sDrive ElseIf _GUICtrlTreeView_GetText($hWndTreeView, $hParent) = StringRegExpReplace(@MyDocumentsDir, "^.*\\", "") Then $iFullPath = @MyDocumentsDir & "\" & $sDrive Else $iFullPath = _GUICtrlTreeView_GetText($hWndTreeView, $hParent) & "\" & $sDrive EndIf While 1 If $hParent = 0 Then Return If FileExists($iFullPath) Then ExitLoop $hParent = _GUICtrlTreeView_GetParentHandle($hWndTreeView, $hParent) If _GUICtrlTreeView_GetText($hWndTreeView, $hParent) = StringRegExpReplace(@DocumentsCommonDir, "^.*\\", "") Then $iFullPath = @DocumentsCommonDir & "\" & $iFullPath ElseIf _GUICtrlTreeView_GetText($hWndTreeView, $hParent) = StringRegExpReplace(@MyDocumentsDir, "^.*\\", "") Then $iFullPath = @DocumentsCommonDir & "\" & $iFullPath Else $iFullPath = _GUICtrlTreeView_GetText($hWndTreeView, $hParent) & "\" & $iFullPath EndIf WEnd $sDrive = $iFullPath EndIf _GUICtrlTreeView_DeleteChildren($hWndTreeView, $hControl) Local $objFolder, $colSubFolder, $objSubFolder, $iSubChild, $iSub $objFolder = $objFSO.GetFolder($sDrive & "\") $colSubFolder = $objFolder.SubFolders For $objSubFolder In $colSubFolder $iSubChild = _GUICtrlTreeView_AddChild($hWndTreeView, $hControl, $objSubFolder.Name, 3, 5) $iSub = _GetSub($objSubFolder.Path) If $iSub Then _GUICtrlTreeView_AddChild($hWndTreeView, $iSubChild, $iSub, 3, 3) Next Return $sDrive EndFunc ;==>_ShellTreeView_GetSelected Func _IsDocDir($sPath, $hControl) If ($sPath = StringRegExpReplace(@DocumentsCommonDir, "^.*\\", "")) And ($hControl = $hCommonDocs) Then Return 1 ElseIf ($sPath = StringRegExpReplace(@MyDocumentsDir, "^.*\\", "")) And ($hControl = $hMyDocs) Then Return 2 Else Return False EndIf EndFunc ;==>_IsDocDir Func _GetSub($sPath) Local $objFolder, $colSubFolder, $objSubFolder $objFolder = $objFSO.GetFolder($sPath & "\") $colSubFolder = $objFolder.SubFolders For $objSubFolder In $colSubFolder If $objSubFolder.Name Then Return $objSubFolder.Name Next EndFunc ;==>_GetSub