Quantcast
Viewing latest article 18
Browse Latest Browse All 12506

Read selected item in Treeview - FileManager

Hi, 

 

i am trying to create a FileManager, now i know there are better programs out there to do it, but i think its fun to try and learn nu things.

Now i am getting stuck in my code i created a button to select a driver/folder after that i put's in the driver/folder contant in the TreeView, but when i select something and click on my button copy.

It returns a 0 instead of something else, when i add a value to the TreeView with: GuiCtrlCreateTreeViewItem and i select that one, then my copy button works.

 

Hope you guys can help me find out/point in the right direction where i am going wrong with this. Any pointers to a nicer GUI or a cleaner script  would be appreciated Image may be NSFW.
Clik here to view.
:)

Below find my code:

AutoIt         
#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <GuiStatusBar.au3> #include <ProgressConstants.au3> #include <TreeViewConstants.au3> #include <WindowsConstants.au3> #include <GuiTreeView.au3> ;------------------------------------------------------------------------------------------------------------------------------------------- #NoTrayIcon ;------------------------------------------------------------------------------------------------------------------------------------------- If @OSVersion   = "WIN_XP" Then     $OS         = "Windows XP" EndIf If @OSVersion   = "WIN_VISTA" Then     $OS         = "Windows Vista" EndIf If @OSVersion   = "WIN_7" Then     $OS         = "Windows 7" EndIf If @OSVersion   = "WIN_8" Then     $OS         = "Windows 8" EndIf If @OSVersion   = "WIN_81" Then     $OS         = "Windows 8.1" EndIf ;------------------------------------------------------------------------------------------------------------------------------------------- $Form1          = GUICreate("", 615, 470, -1, -1, $WS_POPUPWINDOW) $TITLE = GUICtrlCreateLabel("FileManager", 256, 8, 103, 24)     GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")     GUICtrlSetState($TITLE, $GUI_DISABLE) $INFO           = GUICtrlCreateLabel("Hostname:" & @TAB & @ComputerName & @CRLF & "OS:" & @TAB & @TAB & $OS, 16, 437, 200, 60)     GUICtrlSetState($INFO, $GUI_DISABLE) GUICtrlCreateLabel("Source", 16, 16) $SOURCEPROGRESS = GUICtrlCreateProgress(16, 72, 289, 17, $PBS_SMOOTH) $SOURCETREE     = GUICtrlCreateTreeView(16, 104, 289, 305, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)     GUICtrlCreateTreeViewItem("Test1", $SOURCETREE) $SOURCEINPUT    = GUICtrlCreateInput("", 16, 40, 121, 21)     GUICtrlSetState($SOURCEINPUT, $GUI_DISABLE) $SELECTSOURCE   = GUICtrlCreateButton("...", 144, 42, 43, 17) GUICtrlCreateLabel("Target", 568, 16) $TARGETPROGRESS = GUICtrlCreateProgress(312, 72, 289, 17, $PBS_SMOOTH) $TARGETTREE     = GUICtrlCreateTreeView(312, 104, 289, 305, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE) $TARGETINPUT    = GUICtrlCreateInput("", 480, 40, 121, 21)     GUICtrlSetState($TARGETINPUT, $GUI_DISABLE) $SELECTTARGET   = GUICtrlCreateButton("...", 432, 42, 43, 17) $COPY           = GUICtrlCreateButton("Copy", 182, 440, 75, 25) $MOVE           = GUICtrlCreateButton("Move", 270, 440, 75, 25) $DELETE         = GUICtrlCreateButton("Delete", 358, 440, 75, 25) $RENAME         = GUICtrlCreateButton("Rename", 446, 440, 75, 25) $CLOSE          = GUICtrlCreateButton("Exit", 534, 440, 75 , 25) GUISetState(@SW_SHOW) ;------------------------------------------------------------------------------------------------------------------------------------------- While 1     $nMsg = GUIGetMsg()     Switch $nMsg         Case $CLOSE             Exit         Case $SELECTSOURCE             SELECTSOURCE()         Case $SELECTTARGET             SELECTTARGET()         Case $COPY             COPY()     EndSwitch WEnd ;------------------------------------------------------------------------------------------------------------------------------------------- Func SELECTSOURCE()     $VAR = FileSelectFolder("Select Source drive/folder", "")         GUICtrlSetData($SOURCEINPUT, $VAR) Local $iWait    = 10 Local $iSavPos  = 0         Do             For $i = $iSavPos To 100                 GUICtrlSetData($SOURCEPROGRESS, $i)                 Sleep($iWait)                 $iSavPos = $i             Next         Until $iSavPos = 100     _GUICtrlTreeView_BeginUpdate($SOURCETREE)         ListFiles_FolderSOURCE($VAR & "\", 0)     _GUICtrlTreeView_EndUpdate($SOURCETREE) EndFunc ;------------------------------------------------------------------------------------------------------------------------------------------- Func SELECTTARGET()     $VAR = FileSelectFolder("Select Source drive/folder", "")         GUICtrlSetData($TARGETINPUT, $VAR) Local $iWait    = 10 Local $iSavPos  = 0         Do             For $i = $iSavPos To 100                 GUICtrlSetData($TARGETPROGRESS, $i)                 Sleep($iWait)                 $iSavPos = $i             Next         Until $iSavPos = 100     _GUICtrlTreeView_BeginUpdate($TARGETTREE)         ListFiles_FolderTARGET($VAR & "\", 0)     _GUICtrlTreeView_EndUpdate($TARGETTREE) EndFunc ;------------------------------------------------------------------------------------------------------------------------------------------- Func ListFiles_FolderSOURCE($SourceFolder, $Item)         Local $File             If StringRight($SourceFolder, 1) <> "" Then $SourceFolder &= ""         Local $Search = FileFindFirstFile($SourceFolder & "*.*")             If $Search = -1 Then Return     While 1         $File = FileFindNextFile($Search)         If @error Then ExitLoop         If @extended Then         ListFiles_FolderSOURCE($SourceFolder & $File, _GUICtrlTreeView_AddChild($SOURCETREE, $Item, $File))     Else         _GUICtrlTreeView_AddChild($SOURCETREE, $Item, $File)         EndIf     WEnd     FileClose($Search) EndFunc ;------------------------------------------------------------------------------------------------------------------------------------------- Func ListFiles_FolderTARGET($TargetFolder, $Item)         Local $File             If StringRight($TargetFolder, 1) <> "" Then $TargetFolder &= ""         Local $Search = FileFindFirstFile($TargetFolder & "*.*")             If $Search = -1 Then Return     While 1         $File = FileFindNextFile($Search)         If @error Then ExitLoop         If @extended Then         ListFiles_FolderTARGET($TargetFolder & $File, _GUICtrlTreeView_AddChild($TARGETTREE, $Item, $File))     Else         _GUICtrlTreeView_AddChild($TARGETTREE, $Item, $File)         EndIf     WEnd     FileClose($Search) EndFunc ;------------------------------------------------------------------------------------------------------------------------------------------- Func COPY()     $VAR = GUICtrlRead($SOURCETREE)         If $VAR = 0 Then                     MsgBox($MB_SYSTEMMODAL, "Warning!", "No item currently selected")         Else             $sText = GUICtrlRead($VAR, 1) ; Get the text of the treeview item             If $sText == "" Then                 MsgBox($MB_SYSTEMMODAL, "Warning!", "Error while retrieving info about selected item")             Else                 MsgBox($MB_SYSTEMMODAL, "FileManager", "Current item selected is: " & $sText)             EndIf         EndIf EndFunc ;------------------------------------------------------------------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------------------------------------------------------------------

Viewing latest article 18
Browse Latest Browse All 12506

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>