Tjalve

Action on selection in TreeView

7 posts in this topic

Hi everyone. Im creating a GUI for an application. Im usinga  treeview item and i want to add some information to the side of the treeview based on what cilditem you are pressing. For the moment i have a "get info" button that works. But that means that you have to select your child in the treeview, and then press a button to gte the info. I want the info to be visable as soon as you select it.

With uther controls you can just add it to the loop but it doesnt seem to work with tyhe UDF version of the treeview control. Is there anything I can do?

#include <GUIConstantsEx.au3>
#include <GuiTreeView.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>

;~ Create GUI
dim $guilabel[7]
local $currentlevel = 1
Local $hGui = GUICreate( "Grejs", 1000, 500, 600, 300, BitOR( $GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX ) )
Local $iBorderWidth = 4, $aPos = WinGetClientSize( $hGui )
$idTV = _GUICtrlTreeView_Create($hGui, $iBorderWidth, $iBorderWidth, $aPos[0]-2*$iBorderWidth-400, $aPos[1]-2*$iBorderWidth-30 )
$root_level = _GUICtrlTreeView_Add($idTV,0,"Root")
$item1 = _GUICtrlTreeView_AddChild($idTV, $root_level, "child1")
$item2 = _GUICtrlTreeView_AddChild($idTV, $root_level, "child2")
$item3 = _GUICtrlTreeView_AddChild($idTV, $root_level, "child3")

;~ Start Gui
GUISetState()
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
        ExitLoop

        Case $idTV
            MsgBox(0,"","")

    EndSwitch
WEnd
GUIDelete($hGui)

Exit

In this example, i want the msgbox to appear whenevr i select something in the treeview. It ios not my full code, but its an example of the problam i have. Help is much appritiated :)

/G

Share this post


Link to post
Share on other sites



Tjalve,

Here you go:

#include <GUIConstantsEx.au3>
#include <GuiTreeView.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>

; Flag for TV selection change
Global $hItemSelected = 9999

;~ Create GUI
dim $guilabel[7]
local $currentlevel = 1
Local $hGui = GUICreate( "Grejs", 1000, 500, 600, 300, BitOR( $GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX ) )
Local $iBorderWidth = 4, $aPos = WinGetClientSize( $hGui )
$hTV = _GUICtrlTreeView_Create($hGui, $iBorderWidth, $iBorderWidth, $aPos[0]-2*$iBorderWidth-400, $aPos[1]-2*$iBorderWidth-30 )
$root_level = _GUICtrlTreeView_Add($hTV,0,"Root")
$item1 = _GUICtrlTreeView_AddChild($hTV, $root_level, "child1")
$item2 = _GUICtrlTreeView_AddChild($hTV, $root_level, "child2")
$item3 = _GUICtrlTreeView_AddChild($hTV, $root_level, "child3")

;~ Start Gui
GUISetState()

GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
        ExitLoop

    EndSwitch

    ; If flag set
    If $hItemSelected <> 9999 Then
        ; Here is the action
        MsgBox($MB_SYSTEMMODAL, "Selected", _GUICtrlTreeView_GetText($hTV, $hItemSelected))
        ; Clear flag
        $hItemSelected = 9999
    EndIf


WEnd
GUIDelete($hGui)

Exit

Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $wParam
    ; Create NMTREEVIEW structure
    Local $tStruct = DllStructCreate("struct;hwnd hWndFrom;uint_ptr IDFrom;INT Code;endstruct;" & _
            "uint Action;struct;uint OldMask;handle OldhItem;uint OldState;uint OldStateMask;" & _
            "ptr OldText;int OldTextMax;int OldImage;int OldSelectedImage;int OldChildren;lparam OldParam;endstruct;" & _
            "struct;uint NewMask;handle NewhItem;uint NewState;uint NewStateMask;" & _
            "ptr NewText;int NewTextMax;int NewImage;int NewSelectedImage;int NewChildren;lparam NewParam;endstruct;" & _
            "struct;long PointX;long PointY;endstruct", $lParam)
    If DllStructGetData($tStruct, "hWndFrom") = $hTV Then
        Switch DllStructGetData($tStruct, "Code")
            ; If item selection changed
            Case $TVN_SELCHANGEDA, $TVN_SELCHANGEDW
                Local $hItem = DllStructGetData($tStruct, "NewhItem")
                ; Set flag to selected item handle
                If $hItem Then $hItemSelected = $hItem
        EndSwitch
    EndIf
EndFunc

Note that I changed the variable in which you store the return from _GUICtrlTreeView_Create to reflect the fact that you get a handle and not a ControlID - please ask if you do not understand why this is important (or if you have any other questions).

M23

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Hi Melba23 and thank you for your replay.

That work flawlessly! However i still dont really understand. I can deffenently use your code (and i will) but it would be nice to unerstand what is happening.

If i understand it correctly, the UDF fuctions doesnt return a ControlID, but a handle. I suspect there is a good reson for it, but thats boyond my understanding. Anyways, To use Switch and GuiGetMsg() i need a controlID. And since the function does not return one, it wont work.

In your case you are using an IF-statement to check if the itemselected varible has changed. What i dont understand is how that varible change. I see your function and I see some kind of DLL call ore something. But there is no way i would be able to write that myself. So is there some kind of logic to it?

Thank you again for your assistance?

Share this post


Link to post
Share on other sites

Tjalve,

First, let us deal with handles and ControlIDs.

Windows handles are unique identifiers that the OS uses to keep track of everything on the system, such as GUIs and controls, which continually send messages around the system so that everything in the system knows what is going on (which GUI is active, which control has just been actioned, which key was pressed, etc, etc). These messages contain all sorts of data, but essentially explain "which control has just done what".

AutoIt tries to make life simple for you by using ControlIDs to identify its native controls - theses IDs are actually the indIces of an internal array of all controls maintained by AutoIt. So when you look for these ControlIDs in a GUIGetMsg loop you are asking AutoIt to access the Windows message stream and pick put those messages which refer to that control - the OnEvent commands work in a similar manner.

Now to how the script I posted works.

As the UDF functions return handles and not ControlIDs (which as explained above are only returned by AutoIt native functions) we cannot use a GUIGetMsg loop to look for messages, so we have to do it ourselves rather than relying on AutoIt to do it for us. This is where the GUIRegisterMsg command comes into play - it peeks into the Windows message stream and lets us see what is happening. In the script above we are asking to look at WM_NOTIFY messages - a pretty comprehensive set which, amongst many other things, covers selecting items in a TreeView. When a WM_NOTIFY message is detected in the stream AutoIt then runs the allocated function or "handler" where we can examine the message in detail:

  1. We create a data structure to look at the detailed content of the message - this data is stored by Windows and we use one of the message parameters ($lParam) to access it.
  2. We then check that this message was indeed sent by the treeview by looking inside the data structure - we can ignore the vast majority of messages which have been sent by other controls.
  3. Finally we check if the message deals with a change of the selected item in the treeview - and if it does than we know that we have found the message we were looking for.

And there you have it - because the treeview was created by a UDF and not by an internal AutoIt function, we had to recreate what AutoIt does for us "under the hood" and peer into the Windows message stream ourselves to intercept the message telling us that the user had selected another item in the treeview. You can see the same thing happening with tab controls if you read the Tabs tutorial in the Wiki - if you create the tab with the UDF you need to do a lot more work to make it work correctly.

I hope that the above explanation makes you realise how much AutoIt does for you behind the scenes - please ask again if anything is still unclear.

M23

2 people like this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Great @Melba23! Put this somewhere in the Help file?

Skysnake


Skysnake

Why is the snake in the sky?

Share this post


Link to post
Share on other sites
On 2017-02-10 at 2:44 PM, Melba23 said:

Tjalve,

First, let us deal with handles and ControlIDs.

Windows handles are unique identifiers that the OS uses to keep track of everything on the system, such as GUIs and controls, which continually send messages around the system so that everything in the system knows what is going on (which GUI is active, which control has just been actioned, which key was pressed, etc, etc). These messages contain all sorts of data, but essentially explain "which control has just done what".

AutoIt tries to make life simple for you by using ControlIDs to identify its native controls - theses IDs are actually the indIces of an internal array of all controls maintained by AutoIt. So when you look for these ControlIDs in a GUIGetMsg loop you are asking AutoIt to access the Windows message stream and pick put those messages which refer to that control - the OnEvent commands work in a similar manner.

Now to how the script I posted works.

As the UDF functions return handles and not ControlIDs (which as explained above are only returned by AutoIt native functions) we cannot use a GUIGetMsg loop to look for messages, so we have to do it ourselves rather than relying on AutoIt to do it for us. This is where the GUIRegisterMsg command comes into play - it peeks into the Windows message stream and lets us see what is happening. In the script above we are asking to look at WM_NOTIFY messages - a pretty comprehensive set which, amongst many other things, covers selecting items in a TreeView. When a WM_NOTIFY message is detected in the stream AutoIt then runs the allocated function or "handler" where we can examine the message in detail:

  1. We create a data structure to look at the detailed content of the message - this data is stored by Windows and we use one of the message parameters ($lParam) to access it.
  2. We then check that this message was indeed sent by the treeview by looking inside the data structure - we can ignore the vast majority of messages which have been sent by other controls.
  3. Finally we check if the message deals with a change of the selected item in the treeview - and if it does than we know that we have found the message we were looking for.

And there you have it - because the treeview was created by a UDF and not by an internal AutoIt function, we had to recreate what AutoIt does for us "under the hood" and peer into the Windows message stream ourselves to intercept the message telling us that the user had selected another item in the treeview. You can see the same thing happening with tab controls if you read the Tabs tutorial in the Wiki - if you create the tab with the UDF you need to do a lot more work to make it work correctly.

I hope that the above explanation makes you realise how much AutoIt does for you behind the scenes - please ask again if anything is still unclear.

M23

I applaud you sir! Simple and understandable explanation. As i said, I probably would not be able to write it myself (maybe if i copy and paste some of your code :P). But now, atleast i understand whats going on. Great summary and many thanks!

Share this post


Link to post
Share on other sites

#7 ·  Posted

I faced this problem too, my solution was a bit simpler:

$oldItem = ""
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    endSwitch
    
    $newItem = _GUICtrlTreeView_GetSelection($TreeView1)
    If $newItem <> $oldItem Then
        $oldItem = $newItem
        ;do stuff here with $newItem
    endif
wend

Maybe not as optimum, but straightforward.


0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e

Share this post


Link to post
Share on other sites

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

  • Similar Content

    • corgano
      By corgano
      I can't explain easily what i want to do, so i made a picture:

      What i want to do is to specify a treeview item, and then be able to move it right to be a child of the previous item, or left to do the opposite (make a child into a sibling). I also want to move and child items of the target with it, like in the bottom half of the above image depicts. However I didn't see any functions in the help file to move items around. All i want is a button that when pressed, makes the selected item and any of selected item's children move one layer to the right / left. Does anyone know how?

      Edit: something along the lines of _GUICtrlTreeView_Level but SET level
    • Trolleule
      By Trolleule
      Hey,
      i'm building a "Jump To" registry key function and trying to get access to the regedit treeview control like this:
      #include <GUIConstants.au3> #include <GuiTreeView.au3> #include <TreeViewConstants.au3> #include <SendMessage.au3> #include <WinAPI.au3> Global $h_item ShellExecute("regedit.exe") ;~ Local $pid = ProcessExists("regedit.exe") ;~ If $pid Then ;~ $h_tree = WinHandFromPID($pid, "[CLASS:RegEdit_RegEdit]") ;~ WinActivate("[CLASS:RegEdit_RegEdit]", "") ;~ EndIf WinWaitActive("[CLASS:RegEdit_RegEdit]", "") ;~ WinActivate("[CLASS:RegEdit_RegEdit]", "") ;~ WinSetState("[CLASS:RegEdit_RegEdit]", "", @SW_SHOW) ; activate ;~ WinSetState("[CLASS:RegEdit_RegEdit]", "", @SW_RESTORE) ; activate ;~ WinSetState("[CLASS:RegEdit_RegEdit]", "", @SW_RESTORE) ; activate $h_tree = WinGetHandle("[CLASS:RegEdit_RegEdit]", "") ;~ $ret = _WinAPI_ShowWindow($h_tree, @SW_RESTORE) $ctrl = ControlGetHandle($h_tree, "", "[CLASS:SysTreeView32]") ConsoleWrite("$h_tree: " & $h_tree & @CRLF) ConsoleWrite("$ctrl: " & $ctrl & @CRLF) $show = GUICtrlCreateButton("Show", 70, 180, 70, 20) Show() ;~ While 1 ;~ Sleep(200) ;~ WEnd Func Show() $result = "" _SendMessage($ctrl, $WM_SETFOCUS, 0, 0) If @error Then ConsoleWrite("error" & @CRLF) $h_item = _SendMessage($ctrl, $TVM_GETNEXTITEM, $TVGN_ROOT, 0) $split = StringSplit("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders", "\") For $i=1 To $split[0] ConsoleWrite("item bevor findkey: " & $h_item & @CRLF) $h_item = FindKey($h_item, $split[$i]) If $h_item = 0 Then Return _SendMessage($ctrl, $TVM_SELECTITEM, 0x0009, $h_item) ; expand tree _GUICtrlTreeView_Expand($ctrl, $h_item) Next MsgBox(0, "dsfsdf", "sdfsf") Exit EndFunc Func FindKey($hItemParent, $sKey) $h_item = _SendMessage($ctrl, $TVM_GETNEXTITEM, $TVGN_CHILD, $hItemParent) ConsoleWrite("child : " & $h_item & " key: " & $sKey & " parent: " & $hItemParent & " parent text: " & _GUICtrlTreeView_GetText($ctrl, $hItemParent) & @CRLF) While $h_item <> 0 Local $sItemText = _GUICtrlTreeView_GetText($ctrl, $h_item) ConsoleWrite("text : " & $sItemText & @CRLF) If $sItemText = $sKey Then Return $h_item $h_item = _SendMessage($ctrl, $TVM_GETNEXTITEM, $TVGN_NEXT, $h_item) ConsoleWrite("next : " & $h_item & @CRLF) WEnd ConsoleWrite("not found" & @CRLF) Return 0 EndFunc it's working, when i start regedit.exe within my app. But can't get it work when regedit.exe already open. Some ideas?
    • tarretarretarre
      By tarretarretarre
      So I am trying to create a file tree structure Using _FileListToArrayRec with GuiCtrlCreateTreeView. But i have some problems with levels of directorys. In my mind there is nothing wrong with my logic, but obviously it is, since i dont get the output i want  
       
      Here is a printscreen of the outcome, the array is sorted so it feels like it should be pretty easy, but its not
       
      Here is the working code
      #include <File.au3> #include <Array.au3> #include <GUITreeview.au3> #include <WINapiSHELLEX.au3> Local $hGI = GUICreate("test", 500,500) Local $hTreeView = GUICtrlCreateTreeView(0,0,500,500) GUISetState() Local $arr = _GuictrlTreeview__FileListToArrayRec($hTreeView,"C:\Autoit\REMOVE", "*.au3||BackUp;.git*;___TrashCan") _ArrayDisplay($arr) Func _GuictrlTreeview__FileListToArrayRec($hTreeView, $sPath, $sFilter) if StringRight($sPath,1) == "\" Then $sPath = StringLeft($sPath, StringLen($sPath) - 1) if not FileExists($sPath) Then Return SetError(1,0,0) Local $aFileList = _FileListToArrayRec($sPath, $sFilter, $FLTAR_FILESFOLDERS, $FLTAR_RECUR, $FLTAR_SORT, $FLTAR_FULLPATH) if @error Then Return SetError(1,0,0) Local $aParents[1] = [0] Local $sLastParentDirectory = False Local $hLastParentTreeItem = False Local $hLastParentChildItem = False ; Set default icons (late rreplaced with file associated icon $hImageList = _GUIImageList_Create(16, 16, 5, 1) _GUICtrlTreeView_SetNormalImageList($hTreeView, $hImageList) ; Begin tree update _GUICtrlTreeView_BeginUpdate($hTreeView) For $i = 1 To $aFileList[0] Local $sCurFullFilePath = $aFileList[$i] Local $sCurFileName = _Misc_GetFileName($aFileList[$i], False) ;Get da icon Local $hIcon = _WinAPI_ShellExtractAssociatedIcon($sCurFullFilePath, 1) Local $hIcon_Index = _GUIImageList_ReplaceIcon($hImageList, -1, $hIcon) ;If directory If FileGetAttrib($sCurFullFilePath) == "D" Then ; Check if sub has file to add If StringLeft($sCurFullFilePath, StringLen($sLastParentDirectory)) == $sLastParentDirectory Then $hLastParentChildItem = _GUICtrlTreeView_AddChild($hTreeView, $hLastParentTreeItem, $sCurFileName, $hIcon_Index, $hIcon_Index) ;Loop will end here ContinueLoop EndIf ;Create new parent folder & Update parents $sLastParentDirectory = $sCurFullFilePath $hLastParentTreeItem = _GUICtrlTreeView_Add($hTreeView, 0, StringFormat("%s", $sCurFileName), $hIcon_Index, $hIcon_Index) Else If Not $hLastParentChildItem Then ;ConsoleWrite($hLastParentTreeItem&" "&$sCurFileName&@CRLF) _GUICtrlTreeView_AddChild($hTreeView, $hLastParentTreeItem, $sCurFileName, $hIcon_Index, $hIcon_Index) Else _GUICtrlTreeView_AddChild($hTreeView, $hLastParentChildItem, $sCurFileName, $hIcon_Index, $hIcon_Index) EndIf EndIf Next ; End update _GUICtrlTreeView_EndUpdate($hTreeView) Return $aFileList EndFunc Func _Misc_GetFileName($sFilePath, $KeepExtension = True) ; Gets the filename Local $StringSPlit = StringSplit($sFilePath, "\") If Not $KeepExtension Then Return StringRegExpReplace($StringSPlit[$StringSPlit[0]], "\.(.*?)[a-zA-Z1234567890_-]{1,}+", "") Return $StringSPlit[$StringSPlit[0]] EndFunc ;==>_Misc_GetFileName  
      Any tips ?
       
      Thanks in advance
    • Kanashius
      By Kanashius
      This UDF can be used to make a Treeview and/or Listview able to browse Files.
      If you like it, please leave me a comment, also if you have any suggestions to make it better or if you found bugs.
      FileExplorerTreeAndListview_source.zip
    • Wingens
      By Wingens
      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
      Below find my code:
      #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 ;------------------------------------------------------------------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------------------------------------------------------------------