behdadsoft Posted May 26, 2018 Share Posted May 26, 2018 Hi. I wrote below code that contain some parent and child. now i want when i click on only child, give me a message. but problem is when i click on parent, also give me message. dose anyone know how can fix this problem? expandcollapse popup#RequireAdmin #include <File.au3> #include <Array.au3> #include <IE.au3> #include <GuiTreeView.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> ;variables Global $GUI Global $TreeParent[3] Global $TreeChild[4] Global $aStyle = BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS) ;Create GUI Form $GUI = GUICreate("TreeView", 300, 428) GUISetState(@SW_SHOW, $GUI) ;Create TreeView Local $TreeObject = GUICtrlCreateTreeView(0, 0, 300, 428,$aStyle, $WS_EX_CLIENTEDGE) ;Get SubFolders and Add Child to Tree View Item Local $iStart = GUICtrlCreateDummy() for $a = 1 to UBound($TreeParent) - 1 $TreeParent[$a] = GUICtrlCreateTreeViewItem("Parent " & $a,$TreeObject) for $b = 1 to UBound($TreeChild) - 1 $TreeChild[$b] = GUICtrlCreateTreeViewItem("Child " & $b ,$TreeParent[$a]) Next Next Local $iEnd = GUICtrlCreateDummy() ;Repeat Show GUI While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $iStart To $iEnd $treeText = GUICtrlRead($TreeObject, 1) For $c = 1 to UBound($TreeChild) - 1 If $treeText = GUICtrlRead($TreeChild[$c]) Then MsgBox(0,"", $treeText) ExitLoop EndIf next EndSwitch WEnd GUIDelete($GUI) Link to comment Share on other sites More sharing options...
behdadsoft Posted May 27, 2018 Author Share Posted May 27, 2018 (edited) I found it. expandcollapse popup#RequireAdmin #include <File.au3> #include <Array.au3> #include <IE.au3> #include <GuiTreeView.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> ;variables Global $GUI Global $TreeParent[3] Global $TreeChild[4] Global $aStyle = BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS) ;Create GUI Form $GUI = GUICreate("TreeView", 300, 428) GUISetState(@SW_SHOW, $GUI) ;Create TreeView Local $TreeObject = GUICtrlCreateTreeView(0, 0, 300, 428,$aStyle, $WS_EX_CLIENTEDGE) ;Get SubFolders and Add Child to Tree View Item Local $iStart = GUICtrlCreateDummy() for $a = 1 to UBound($TreeParent) - 1 $TreeParent[$a] = GUICtrlCreateTreeViewItem("Parent " & $a,$TreeObject) for $b = 1 to UBound($TreeChild) - 1 $TreeChild[$b] = GUICtrlCreateTreeViewItem("Child " & $b ,$TreeParent[$a]) Next Next Local $iEnd = GUICtrlCreateDummy() ;Repeat Show GUI While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $iStart To $iEnd $treeText = GUICtrlRead($TreeObject, 1) For $c = 1 to UBound($TreeChild) - 1 If $treeText = GUICtrlRead($TreeChild[$c], 1) Then MsgBox(0,"", $treeText) ExitLoop EndIf next EndSwitch WEnd GUIDelete($GUI) Edited May 27, 2018 by behdadsoft Link to comment Share on other sites More sharing options...
behdadsoft Posted May 27, 2018 Author Share Posted May 27, 2018 (edited) Now, in this part of above code i want instead of use strings ("Parent" and "Child"), use record folder in Script directory. ;Get SubFolders and Add Child to Tree View Item Local $iStart = GUICtrlCreateDummy() for $a = 1 to UBound($TreeParent) - 1 $TreeParent[$a] = GUICtrlCreateTreeViewItem("Parent " & $a,$TreeObject) for $b = 1 to UBound($TreeChild) - 1 $TreeChild[$b] = GUICtrlCreateTreeViewItem("Child " & $b ,$TreeParent[$a]) Next Next Local $iEnd = GUICtrlCreateDummy() This is new code : expandcollapse popup#RequireAdmin #include <File.au3> #include <Array.au3> #include <IE.au3> #include <GuiTreeView.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> ;variables Global Const $Path = @ScriptDir Global $GUI Global $RecordChildFolder Global $RecordFiles Global $GetFolderList Dim $TreeParent[1] Dim $TreeChild[7] Global $aStyle = BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS) ;Create GUI Form $GUI = GUICreate("Autorun", 800, 600) GUISetState(@SW_SHOW, $GUI) ;Create TreeView Local $TreeObject = GUICtrlCreateTreeView(2, 170, 300, 428,$aStyle, $WS_EX_CLIENTEDGE) ;Get Folder name to Array $GetFolderList = _FileListToArray($Path,"*",$FLTA_FOLDERS) ReDim $TreeParent[UBound($GetFolderList)] ;Get SubFolders and Add Child to Tree View Item Local $iStart = GUICtrlCreateDummy() for $a = 1 to UBound($TreeParent) - 1 $TreeParent[$a] = GUICtrlCreateTreeViewItem($GetFolderList[$a],$TreeObject) $RecordChildFolder = _FileListToArrayRec($GetFolderList[$a],"*",$FLTAR_FOLDERS,$FLTAR_RECUR,$FLTAR_SORT) for $b = 1 to UBound($RecordChildFolder) - 1 $TreeChild[$b] = GUICtrlCreateTreeViewItem($RecordChildFolder[$b] ,$TreeParent[$a]) Next Next Local $iEnd = GUICtrlCreateDummy() ;Repeat Show GUI While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $iStart To $iEnd $treeText = GUICtrlRead($TreeObject, 1) For $q = 1 to UBound($TreeChild) - 1 If $treeText = GUICtrlRead($TreeChild[$q], 1) Then MsgBox(64,"", $treeText) ExitLoop EndIf next EndSwitch WEnd GUIDelete($GUI) Now I have same problem in like my first post. (when i click on parent and child objects, give message. while i only want when i click on child, give me a message). Edited May 27, 2018 by behdadsoft Link to comment Share on other sites More sharing options...
LarsJ Posted May 27, 2018 Share Posted May 27, 2018 You do it this way: expandcollapse popup#RequireAdmin #include <File.au3> #include <Array.au3> #include <IE.au3> #include <GuiTreeView.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> ;variables Global $GUI Global $TreeParent[3] Global $TreeChild[6], $iChilds = 0 Global $aStyle = BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS) ;Create GUI Form $GUI = GUICreate("TreeView", 300, 428) GUISetState(@SW_SHOW, $GUI) ;Create TreeView Local $TreeObject = GUICtrlCreateTreeView(0, 0, 300, 428,$aStyle, $WS_EX_CLIENTEDGE) ;Get SubFolders and Add Child to Tree View Item Local $iStart = GUICtrlCreateDummy() for $a = 1 to UBound($TreeParent) - 1 $TreeParent[$a] = GUICtrlCreateTreeViewItem("Parent " & $a,$TreeObject) for $b = 0 to UBound($TreeChild) / 2 - 1 $TreeChild[$iChilds] = GUICtrlCreateTreeViewItem("Child " & $iChilds ,$TreeParent[$a]) $iChilds += 1 Next Next Local $iEnd = GUICtrlCreateDummy() ;Repeat Show GUI While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $iStart + 1 To $iEnd - 1 For $c = 0 to $iChilds - 1 If $iMsg = $TreeChild[$c] Then MsgBox(0,"", GUICtrlRead($iMsg, 1)) ExitLoop EndIf next Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd GUIDelete($GUI) behdadsoft 1 Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
behdadsoft Posted May 27, 2018 Author Share Posted May 27, 2018 Thanks I was fixed above code in this block: For $q = 0 to UBound($TreeChild) - 1 If $treeText = GUICtrlRead($TreeChild[$q], 1) Then MsgBox(64,"", $treeText) ExitLoop EndIf next in this code i don't have same parent and child, if possible please tell me how can fix this problem in new code with my own way. expandcollapse popup#RequireAdmin #include <File.au3> #include <Array.au3> #include <IE.au3> #include <GuiTreeView.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> ;variables Global Const $Path = @ScriptDir Global $GUI Global $RecordChildFolder Global $RecordFiles Global $GetFolderList Dim $TreeParent[1] Dim $TreeChild[7] Global $aStyle = BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS) ;Create GUI Form $GUI = GUICreate("Autorun", 800, 600) GUISetState(@SW_SHOW, $GUI) ;Create TreeView Local $TreeObject = GUICtrlCreateTreeView(2, 170, 300, 428,$aStyle, $WS_EX_CLIENTEDGE) ;Get Folder name to Array $GetFolderList = _FileListToArray($Path,"*",$FLTA_FOLDERS) ReDim $TreeParent[UBound($GetFolderList)] ;Get SubFolders and Add Child to Tree View Item Local $iStart = GUICtrlCreateDummy() for $a = 1 to UBound($TreeParent) - 1 $TreeParent[$a] = GUICtrlCreateTreeViewItem($GetFolderList[$a],$TreeObject) $RecordChildFolder = _FileListToArrayRec($GetFolderList[$a],"*",$FLTAR_FOLDERS,$FLTAR_RECUR,$FLTAR_SORT) for $b = 1 to UBound($RecordChildFolder) - 1 $TreeChild[$b] = GUICtrlCreateTreeViewItem($RecordChildFolder[$b] ,$TreeParent[$a]) Next Next Local $iEnd = GUICtrlCreateDummy() ;Repeat Show GUI While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $iStart To $iEnd $treeText = GUICtrlRead($TreeObject, 1) For $q = 1 to UBound($TreeChild) - 1 If $treeText = GUICtrlRead($TreeChild[$q], 1) Then MsgBox(64,"", $treeText) ExitLoop EndIf next EndSwitch WEnd GUIDelete($GUI) Link to comment Share on other sites More sharing options...
LarsJ Posted May 27, 2018 Share Posted May 27, 2018 When it comes to reading a folder structure, more efficient techniques should be used because there can be many folders. Here the item level in the treeview is calculated. If the level is larger than 1 it's not a top folder: expandcollapse popup#RequireAdmin #include <File.au3> #include <Array.au3> #include <IE.au3> #include <GuiTreeView.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> ;variables Global Const $Path = @ScriptDir Global $GUI Global $RecordChildFolder Global $RecordFiles Global $GetFolderList Dim $TreeParent[1] Dim $TreeChild[100], $iChilds = 0 Global $aStyle = BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS) ;Create GUI Form $GUI = GUICreate("Autorun", 800, 600) GUISetState(@SW_SHOW, $GUI) ;Create TreeView Local $TreeObject = GUICtrlCreateTreeView(2, 170, 300, 428,$aStyle, $WS_EX_CLIENTEDGE) $hTreeObject = GUICtrlGetHandle( $TreeObject ) ;Get Folder name to Array $GetFolderList = _FileListToArray($Path,"*",$FLTA_FOLDERS) ReDim $TreeParent[UBound($GetFolderList)] ;Get SubFolders and Add Child to Tree View Item Local $iStart = GUICtrlCreateDummy() for $a = 1 to UBound($TreeParent) - 1 $TreeParent[$a] = GUICtrlCreateTreeViewItem($GetFolderList[$a],$TreeObject) $RecordChildFolder = _FileListToArrayRec($GetFolderList[$a],"*",$FLTAR_FOLDERS,$FLTAR_RECUR,$FLTAR_SORT) for $b = 1 to UBound($RecordChildFolder) - 1 $TreeChild[$b] = GUICtrlCreateTreeViewItem($RecordChildFolder[$b] ,$TreeParent[$a]) $iChilds += 1 Next Next Local $iEnd = GUICtrlCreateDummy() ;Repeat Show GUI While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $iStart - 1 To $iEnd - 1 ; Calculate item treeview level Local $iLevel = 0, $hItem = GUICtrlGetHandle( $iMsg ) While $hItem And $iLevel < 2 $hItem = _SendMessage( $hTreeObject, $TVM_GETNEXTITEM, $TVGN_PARENT, $hItem, 0, "wparam", "handle", "handle") $iLevel += 1 WEnd ; If item treeview level > 1 it's not a top folder If $iLevel > 1 Then MsgBox(0,"", GUICtrlRead($iMsg, 1)) Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd GUIDelete($GUI) Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
behdadsoft Posted May 27, 2018 Author Share Posted May 27, 2018 Thanks LarsJ Now work very well. but i need know two thing in your way: 1- why used -1 for this part? Case $iStart - 1 To $iEnd - 1 2- what is your mean about level? Can you explain more? Link to comment Share on other sites More sharing options...
LarsJ Posted May 27, 2018 Share Posted May 27, 2018 It should be: Case $iStart + 1 To $iEnd - 1 You are only interested in treeview item controls. $iStart and $iEnd are dummy controls, so let's exclude both. The level is the number of vertical lines in front of a treeview item. Here all parent items are level 1 and all child items are level 2. behdadsoft 1 Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
behdadsoft Posted May 28, 2018 Author Share Posted May 28, 2018 OK, Thanks. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now