Explorer selber basteln

  • Halle Zusammen:

    will einen Explorer Programmieren, um meine Script-Skills zu verbessern....


    Folgendes Problem: suche einen Befehl der erkennt, wenn ich das erste mal auf das "+" klicke, damit ich ihm sagen kann, dass er weitere Ordner im Unterordner hinzufügen kann...! denn ich kann ja nich die komplette liste der Ordner am Anfang erstellen.


    Wisst ihr was ich meine??


    Folgendese Quelltext:

    [autoit]

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

    [/autoit][autoit][/autoit][autoit]

    Local $hItem[20], $hChildItem[30], $iYItem = 0, $iRand, $hTreeView
    Local $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS)
    $Form1 = GUICreate("Form1", 633, 454, 192, 114)
    $hTreeView = GUICtrlCreateTreeView(2, 2, 600, 268, $iStyle, $WS_EX_CLIENTEDGE)
    GUISetState(@SW_SHOW)
    $hStateImage = _GUIImageList_Create(16, 16, 5, 3)
    _GUIImageList_AddIcon($hStateImage, "shell32.dll", 3)
    _GUIImageList_AddIcon($hStateImage, "shell32.dll", 4)
    _GUICtrlTreeView_SetStateImageList($hTreeView, $hStateImage) ;Zum Verbinden der Icons mit den NetzwerkBäumen
    $drives = DriveGetDrive ("ALL")
    _GUICtrlTreeView_BeginUpdate($hTreeView)
    For $x = 1 To $drives[0]
    $hItem[$x] = _GUICtrlTreeView_Add($hTreeView, 0, $drives[$x], 4, 5)
    _GUICtrlTreeView_SetStateImageIndex($hTreeView, $hItem[$x], 1)
    For $y = 1 To 3
    $hChildItem[$iYItem] = _GUICtrlTreeView_AddChild($hTreeView, $hItem[$x], "New Child", 0, 3)
    _GUICtrlTreeView_SetStateImageIndex($hTreeView, $hChildItem[$iYItem], 1)
    $iYItem += 1
    Next
    $iYItem = 0
    Next

    [/autoit][autoit][/autoit][autoit]

    _GUICtrlTreeView_EndUpdate($hTreeView)

    [/autoit][autoit][/autoit][autoit]

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    EndSwitch
    WEnd

    [/autoit]


    Befehl schon gesucht und leider nicht gefunden: freu mich über eure hilfe! :rock:

    Einmal editiert, zuletzt von Mr_gitarre (30. April 2010 um 08:40)

  • @Mr_gitarre


    Hier hast Du auf die Schnelle.


    Spoiler anzeigen
    [autoit]

    AutoItSetOption('MustDeclareVars', 1)
    AutoItSetOption('GUIOnEventMode', 1)
    #include <GUIConstantsEx.au3>
    #include <GUIListBox.au3>
    #include <WindowsConstants.au3>
    #include <GuiConstantsEx.au3>
    #include <GuiTreeView.au3>
    _Main()
    Func _Main()
    _CreateGUI()
    GUIRegisterMsg($WM_NOTIFY, '_WM_NOTIFY')
    While 1
    Sleep(100)
    WEnd
    EndFunc ;==>_Main

    [/autoit] [autoit][/autoit] [autoit]

    Func _CreateGUI()
    Local $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS)
    Local $hForm = GUICreate('MyExplorer', 633, 454, 192, 114)
    Local $hTreeView = GUICtrlCreateTreeView(2, 2, 600, 268, $iStyle, $WS_EX_CLIENTEDGE)
    Local $hStateImage = _GUIImageList_Create(16, 16, 5, 3)
    _GUIImageList_AddIcon($hStateImage, 'shell32.dll', 3)
    _GUIImageList_AddIcon($hStateImage, 'shell32.dll', 4)
    _GUICtrlTreeView_SetStateImageList($hTreeView, $hStateImage)
    _GUICtrlTreeView_BeginUpdate($hTreeView)
    Local $Drives = DriveGetDrive('ALL')
    For $i = 1 To $Drives[0]
    Local $htrvNode = _GUICtrlTreeView_Add($hTreeView, 0, $Drives[$i], 4, 5)
    _GUICtrlTreeView_SetStateImageIndex($hTreeView, $htrvNode, 1)
    _GUICtrlTreeView_AddChild($hTreeView, $htrvNode, '*', 0, 3)
    Next
    _GUICtrlTreeView_EndUpdate($hTreeView)
    GUISetOnEvent($GUI_EVENT_CLOSE, '_GUIEvents')
    GUISetState(@SW_SHOW)
    Return $hForm
    EndFunc ;==>_CreateGUI
    Func _GUIEvents()
    Select
    Case @GUI_CtrlId = $GUI_EVENT_CLOSE
    Exit 0
    EndSelect
    EndFunc ;==>_GUIEvents
    Func _WM_NOTIFY($p_hWnd, $p_iMsg, $p_iwParam, $p_ilParam)
    Local $hTreeview = ControlGetHandle('[TITLE:MyExplorer; CLASS:AutoIt v3 GUI]', '', '[CLASS:SysTreeView32; INSTANCE:1]')
    Local $tNMHDR = DllStructCreate($tagNMHDR, $p_ilParam)
    Local $hWndFrom = DllStructGetData($tNMHDR, 'hWndFrom')
    Local $iIDFrom = DllStructGetData($tNMHDR, 'idFrom')
    Local $iCode = DllStructGetData($tNMHDR, 'Code')
    Switch $hWndFrom
    Case $hTreeview
    Switch $iCode
    Case $NM_CLICK
    Case $TVN_SELCHANGINGW
    Case $TVN_ITEMEXPANDINGW, $TVN_ITEMEXPANDEDW
    Local $tInfo = DllStructCreate($tagNMTREEVIEW, $p_ilParam)
    If DllStructGetData($tInfo, 'Action') = $TVE_EXPAND Then
    Local $htrvNode = DllStructGetData($tInfo, 'NewhItem')
    Local $htrvFirstNode = _GUICtrlTreeView_GetFirstChild($hTreeview, $htrvNode)
    If _GUICtrlTreeView_GetText($hTreeview, $htrvFirstNode) = '*' Then
    _GUICtrlTreeView_Delete($hTreeview, $htrvFirstNode)
    _AddTreeViewNode($hTreeview, $htrvNode)
    EndIf
    EndIf
    EndSwitch
    EndSwitch
    EndFunc ;==>_WM_NOTIFY
    Func _AddTreeViewNode($p_hTreeview, $p_htrvNode)
    local $strvNodePath = StringReplace(_GUICtrlTreeView_GetTree($p_hTreeview, $p_htrvNode), '|', '\')
    Local $hSearch = FileFindFirstFile($strvNodePath & '\*.*')
    While 1
    If $hSearch = -1 Then
    ExitLoop
    EndIf
    Local $hFile = FileFindNextFile($hSearch)
    If @error Then ExitLoop
    Local $sFullFilePath = $strvNodePath & '\' & $hFile
    Local $sFileAttributes = FileGetAttrib($sFullFilePath)
    If StringInStr($sFileAttributes, 'D') Then
    Local $htrvNewNode= _GUICtrlTreeView_AddChild($p_hTreeview, $p_htrvNode, $hFile)
    _GUICtrlTreeView_SetStateImageIndex($p_hTreeview, $htrvNewNode, 1)
    _GUICtrlTreeView_AddChild($p_hTreeview, $htrvNewNode, '*')
    EndIf
    WEnd
    FileClose($hSearch)
    EndFunc ;==>_AddTreeViewNode

    [/autoit]
  • Ich habe hier auch noch ein Beispiel liegen (Autor unbekannt):

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>
    #include <GuiImageList.au3>
    #include <GuiTreeView.au3>
    #include <StructureConstants.au3>
    #include <TreeViewConstants.au3>
    #include <WindowsConstants.au3>

    [/autoit] [autoit][/autoit] [autoit]

    $hGui = GUICreate('FileExplorer', 400, 400)
    $hTreeview = GUICtrlCreateTreeView(10, 10, 380, 360)
    $hWndTreeview = GUICtrlGetHandle($hTreeview)
    $hOk = GUICtrlCreateButton('Ok', 240, 375, 60, 22)
    $hCancel = GUICtrlCreateButton('Cancel', 320, 375, 60, 22)

    [/autoit] [autoit][/autoit] [autoit]

    $hImage = _GUIImageList_Create(16, 16, 5, 1)
    _GUIImageList_AddIcon($hImage, 'shell32.dll', 3) ; Verzeichnis-Icon
    _GUIImageList_AddIcon($hImage, 'shell32.dll', 110) ; Verzeichnis-Icon mit Haken
    _GUIImageList_AddIcon($hImage, 'shell32.dll', 1) ; Datei-Icon
    _GUIImageList_AddIcon($hImage, 'shell32.dll', 5) ; Diskette
    _GUIImageList_AddIcon($hImage, 'shell32.dll', 7) ; Wechseldatenträger
    _GUIImageList_AddIcon($hImage, 'shell32.dll', 8) ; Festplatte
    _GUIImageList_AddIcon($hImage, 'shell32.dll', 11) ; CDROM
    _GUIImageList_AddIcon($hImage, 'shell32.dll', 12) ; Netzwerklaufwerk
    _GUIImageList_AddIcon($hImage, 'shell32.dll', 53) ; Unbekannt
    _GUICtrlTreeView_SetNormalImageList($hTreeview, $hImage)

    [/autoit] [autoit][/autoit] [autoit]

    GUISetState()
    GUICtrlSetStyle($hTreeview, Default, $WS_EX_COMPOSITED + $WS_EX_CLIENTEDGE)

    [/autoit] [autoit][/autoit] [autoit]

    $aDrives = DriveGetDrive('ALL')
    ToolTip('Please wait...', Default, Default, 'Read Directory', 1)
    For $i = 1 To $aDrives[0]
    $iLWindex = 0
    Switch DriveGetType($aDrives[$i])
    Case 'Fixed'
    $iLWindex = 5
    Case 'CDROM'
    $iLWindex = 6
    Case 'RAMDisk'
    $iLWindex = 7
    Case 'Removable'
    $iLWindex = 4
    If StringLeft($aDrives[$i], 2) = 'a:' Or StringLeft($aDrives[$i], 2) = 'b:' Then $iLWindex = 3
    Case Else
    $iLWindex = 8
    EndSwitch
    $hRoot = _GUICtrlTreeView_Add($hTreeview, $hTreeview, StringUpper($aDrives[$i]), $iLWindex, $iLWindex)
    If DriveStatus($aDrives[$i]) <> 'READY' Then ContinueLoop
    _GUICtrlTreeView_BeginUpdate($hTreeview)
    _GUICtrlTreeView_FileExplorerRecursive($hTreeview, $hRoot, $aDrives[$i], 1)
    _GUICtrlTreeView_EndUpdate($hTreeview)
    Next
    ToolTip('')

    [/autoit] [autoit][/autoit] [autoit]

    GUIRegisterMsg($WM_NOTIFY, '_WM_NOTIFY')
    While True
    Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE, $hCancel
    Exit
    Case $hOk
    $iSelect = _GUICtrlTreeView_GetSelection($hTreeview)
    $sTree = StringReplace(_GUICtrlTreeView_GetTree($hTreeview, $iSelect), '|', '\')
    MsgBox(0, 'Selected Path/File', $sTree)
    EndSwitch
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    GUIRegisterMsg($WM_NOTIFY, '')
    Local $hWndFrom, $iCode, $tNMHDR
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, 'hWndFrom'))
    $iCode = DllStructGetData($tNMHDR, 'Code')
    If $hWndFrom = $hWndTreeview And $iCode = $NM_CLICK Then
    ToolTip('Please wait...', Default, Default, 'Read Directory', 1)
    _GUICtrlTreeView_FileExplorer($hGui, $hTreeview)
    ToolTip('')
    EndIf
    GUIRegisterMsg($WM_NOTIFY, '_WM_NOTIFY')
    Return $GUI_RUNDEFMSG
    EndFunc ;==>_WM_NOTIFY

    [/autoit] [autoit][/autoit] [autoit]

    Func _GUICtrlTreeView_FileExplorer($hGui, $hTreeview)
    Local $aTVPos, $aPos, $hItem, $hChild, $sTree
    $aTVPos = ControlGetPos($hGui, '', $hTreeview)
    $aPos = GUIGetCursorInfo($hGui)
    $hItem = _GUICtrlTreeView_HitTestItem($hTreeview, $aPos[0], $aPos[1] - $aTVPos[1])
    If _GUICtrlTreeView_GetExpanded($hTreeview, $hItem) Then Return
    $hChild = _GUICtrlTreeView_GetFirstChild($hTreeview, $hItem)
    If $hChild <> 0 Then
    _GUICtrlTreeView_BeginUpdate($hTreeview)
    $sTree = StringReplace(_GUICtrlTreeView_GetTree($hTreeview, $hChild), '|', '\')
    _GUICtrlTreeView_DeleteChildren($hTreeview, $hChild)
    _GUICtrlTreeView_FileExplorerRecursive($hTreeview, $hChild, $sTree, 1)
    Do
    $hChild = _GUICtrlTreeView_GetNextChild($hTreeview, $hChild)
    If $hChild <> 0 Then
    $sTree = StringReplace(_GUICtrlTreeView_GetTree($hTreeview, $hChild), '|', '\')
    _GUICtrlTreeView_DeleteChildren($hTreeview, $hChild)
    $iTimer = TimerInit()
    _GUICtrlTreeView_FileExplorerRecursive($hTreeview, $hChild, $sTree, 1)
    EndIf
    Until $hChild = 0
    _GUICtrlTreeView_EndUpdate($hTreeview)
    EndIf
    EndFunc ;==>_GUICtrlTreeView_FileExplorer

    [/autoit] [autoit][/autoit] [autoit]

    Func _GUICtrlTreeView_FileExplorerRecursive($hTreeview, $hItem, $sPath, $iRec)
    Local $aDirList, $aFileList, $tmp
    If StringRight($sPath, 1) <> '\' Then $sPath &= '\'
    $iRec -= 1
    $aDirList = _MyFileListToArray($sPath, 2)
    If IsArray($aDirList) Then
    For $sDir In $aDirList
    $tmp = _GUICtrlTreeView_AddChild($hTreeview, $hItem, $sDir, 0, 1)
    If $iRec > 0 Then _GUICtrlTreeView_FileExplorerRecursive($hTreeview, $tmp, $sPath & $sDir, $iRec)
    Next
    EndIf
    $aFileList = _MyFileListToArray($sPath, 1)
    If IsArray($aFileList) Then
    For $sFile In $aFileList
    $tmp = _GUICtrlTreeView_AddChild($hTreeview, $hItem, $sFile, 2, 2)
    Next
    EndIf
    EndFunc ;==>_GUICtrlTreeView_FileExplorerRecursive

    [/autoit] [autoit][/autoit] [autoit]

    Func _MyFileListToArray($sPath, $iFlag)
    Local $sFileList = '', $hSearch, $sFile
    $hSearch = FileFindFirstFile($sPath & '*')
    If @error Then Return
    While True
    $sFile = FileFindNextFile($hSearch)
    If @error Then ExitLoop
    If ($iFlag + @extended = 2) Then ContinueLoop
    $sFileList &= $sFile & '|'
    WEnd
    FileClose($hSearch)
    If $sFileList = '' Then Return
    Return StringSplit(StringTrimRight($sFileList, 1), '|', 2)
    EndFunc ;==>__FileListToArray

    [/autoit]

    Zur Nutzung dieses Forum's, ist ein Übersetzer für folgende Begriffe unerlässlich:

    "On-Bort, weier, verscheiden, schädliges, Butten steyling, näckstet, Parr, Porblem, scripe, Kompletenz, harken, manuel zu extramieren, geckukt, würglich, excell, acces oder Compilevorgeng"