Zedna Posted May 29, 2007 Share Posted May 29, 2007 (edited) I used this in my project to automatize PatchMaker application.There is no other way to add folder to ListView only by Button which populates standard Windows FileSelectFolder dialog.So I did this helper function which parse desired path to be selected andgoes through TreeView control and selects/expands path partsand finally click on OK button.So I share it here for other users.expandcollapse popup; note: "Vyhledat složku" is localized standard dialog title on Czech Windows ; on English Windows it will be probably "Select folder" #include <GuiTreeView.au3> ; test code with FileSelectFolder (simulation of another process) Run(@AutoItExe & ' /AutoIt3ExecuteLine "FileSelectFolder(''Select folder test'', '''')"') _SelectFolder("Vyhledat složku", "Select folder test", 'C:\Program Files\Autoit3') Func _SelectFolder($title, $text, $path_to_select) ; last char musn't be '\' If StringRight($path_to_select,1) = '\' Then $path_to_select = StringTrimRight($path_to_select,1) WinActivate($title, $text) WinWaitActive($title, $text) $hTree = ControlGetHandle($title, $text, "SysTreeView321") _ParsePath($hTree, $path_to_select) If @error Then ControlClick($title, $text, "Button2") ; Cancel Exit EndIf ; only test of final selection (not needed) ; uncomment to see final selection ;~ $hNode = _GUICtrlTreeView_GetSelection($hTree) ;~ $path_return = _GUICtrlTreeView_GetText($hTree, $hNode) ;~ MsgBox(0,'Selected node text',$path_return) ControlClick($title, $text, "Button1") ; OK WinWaitClose($title, $text) EndFunc ; parse path to parts and goes through TreeView and selects/expands path parts Func _ParsePath($hTree, $path) $path2 = StringSplit($path, '\') ; first part searching is little nonstandard $tmp = '(' & $path2[1] & ')' ; (C:) $hNext = _GUICtrlTreeView_FindItem($hTree, $tmp, True) If $hNext = 0 Then MsgBox(48,'Error','Not found TreeView node! path=' & $path & ' part=' & $tmp) SetError(1) Return EndIf ; for remaining parts searching is the same For $i = 2 To $path2[0] $found = False _GUICtrlTreeView_Expand($hTree, $hNext) $hNext = _GUICtrlTreeView_GetFirstChild($hTree, $hNext) While $hNext <> 0 If _GUICtrlTreeView_GetText($hTree, $hNext) = $path2[$i] Then $found = True ExitLoop EndIf $hNext = _GUICtrlTreeView_GetNextSibling($hTree, $hNext) WEnd If Not $found Then MsgBox(48,'Error','Not found TreeView node! path=' & $path & ' part=' & $path2[$i]) SetError(1) Return EndIf Next _GUICtrlTreeView_SelectItem($hTree, $hNext) EndFuncEDIT: - 26.8.2008: updated from #include <A3LTreeView.au3> to #include <GuiTreeView.au3> Edited August 26, 2008 by Zedna robertocm 1 Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Gif Posted May 29, 2007 Share Posted May 29, 2007 I used this in my project to automatize PatchMaker application. There is no other way to add folder to ListView only by Button which populates standard Windows FileSelectFolder dialog. So I did this helper function which parse desired path to be selected and goes through TreeView control and selects/expands path parts and finally click on OK button. So I share it here for other users. Note: It uses TreeView functions from PaulIA's Auto3Lib library. expandcollapse popup; note: "Vyhledat složku" is localized standard dialog title on Czech Windows ; on English Windows it will be probably "Select folder" #include <A3LTreeView.au3> ; test code with FileSelectFolder (simulation of another process) Run(@AutoItExe & ' /AutoIt3ExecuteLine "FileSelectFolder(''Select folder test'', '''')"') _SelectFolder("Vyhledat složku", "Select folder test", 'C:\Program Files\Autoit3') Func _SelectFolder($title, $text, $path_to_select) ; last char musn't be '\' If StringRight($path_to_select,1) = '\' Then $path_to_select = StringTrimRight($path_to_select,1) WinActivate($title, $text) WinWaitActive($title, $text) $hTree = ControlGetHandle($title, $text, "SysTreeView321") _ParsePath($hTree, $path_to_select) If @error Then ControlClick($title, $text, "Button2") ; Cancel Exit EndIf ; only test of final selection (not needed) ; uncomment to see final selection ;~ $hNode = _TreeView_GetSelection($hTree) ;~ $path_return = _TreeView_GetText ($hTree, $hNode) ;~ MsgBox(0,'Selected node text',$path_return) ControlClick($title, $text, "Button1") ; OK WinWaitClose($title, $text) EndFunc ; parse path to parts and goes through TreeView and selects/expands path parts Func _ParsePath($hTree, $path) $path2 = StringSplit($path, '\') ; first part searching is little nonstandard $tmp = '(' & $path2[1] & ')' ; (C:) $hNext = _TreeView_FindNode($hTree, $tmp, True) If $hNext = 0 Then MsgBox(48,'Error','Not found TreeView node! path=' & $path & ' part=' & $tmp) SetError(1) Return EndIf ; for remaining parts searching is the same For $i = 2 To $path2[0] $found = False _TreeView_Expand($hTree, $hNext) $hNext = _TreeView_GetFirstChild($hTree, $hNext) While $hNext <> 0 If _TreeView_GetText ($hTree, $hNext) = $path2[$i] Then $found = True ExitLoop EndIf $hNext = _TreeView_GetNextSibling($hTree, $hNext) WEnd If Not $found Then MsgBox(48,'Error','Not found TreeView node! path=' & $path & ' part=' & $path2[$i]) SetError(1) Return EndIf Next _TreeView_Select($hTree, $hNext) EndFunc Very, very smart and handy. Post also an example script Link to comment Share on other sites More sharing options...
Zedna Posted May 29, 2007 Author Share Posted May 29, 2007 (edited) Very, very smart and handy. Post also an example script It's also example script. Read these first lines: ; note: "Vyhledat složku" is localized standard dialog title on Czech Windows ; on English Windows it will be probably "Select folder" #include <GuiTreeView.au3> ; test code with FileSelectFolder (simulation of another process) Run(@AutoItExe & ' /AutoIt3ExecuteLine "FileSelectFolder(''Select folder test'', '''')"') _SelectFolder("Vyhledat složku", "Select folder test", 'C:\Program Files\Autoit3') Edited August 26, 2008 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Gif Posted May 29, 2007 Share Posted May 29, 2007 Ok very good! Link to comment Share on other sites More sharing options...
Zedna Posted August 26, 2008 Author Share Posted August 26, 2008 (edited) Updated first post: - updated from #include <A3LTreeView.au3> to #include <GuiTreeView.au3> Edited August 26, 2008 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search 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