通过TreeView 编写资源管理器,如何实现更高效!
问题如标题通过TreeView 编写资源管理器,如何实现更高效!
我目前的思路是通过Dos命令(Dir /ogn /b)的回显来实现的,但是感觉效果不好
感觉问题不少:
1.遍历速度很慢
2.代码没有得到很好的优化
也不知有没比DOS回显更高效的方法?
希望各路大神们,能给点意见,提些有建设性的建议,不甚感激!#include <GUIConstantsEx.au3>
#include <GuiTreeView.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
$Debug_TV = False ; Check ClassName being passed to functions, set to True and use a handle to another control to see it work
Local $hItem, $hTreeView
Local $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS)
GUICreate("TreeView Set Icon", 400, 500)
$hTreeView = GUICtrlCreateTreeView(2, 2, 396, 388, $iStyle, $WS_EX_CLIENTEDGE)
GUISetState()
_GUICtrlTreeView_BeginUpdate($hTreeView)
Global $foo = Run(@ComSpec & " /c " & 'dir c:\ /ogn /b ', "", @SW_HIDE,$STDOUT_CHILD)
ProcessWaitClose($foo)
Global $line
$line = StdoutRead($foo)
$cow = StringSplit($line, @CRLF, 1)
$n=$cow
For $x = 1 To $n-1
$tm=GUICtrlCreateTreeViewItem($cow[$x], $hTreeView)
If StringInStr(FileGetAttrib("c:\"&$cow[$x]), "D")Then
$foo1 = Run(@ComSpec & " /c " & 'dir c:\"'&$cow[$x]&'" /ogn /b ', "", @SW_HIDE,$STDOUT_CHILD)
ProcessWaitClose($foo1)
Global $line1
$line1 = StdoutRead($foo1)
$cow1 = StringSplit($line1, @CRLF, 1)
$n1=$cow1
For $x1 = 1 To $n1-1
$m=GUICtrlCreateTreeViewItem($cow1[$x1], $tm)
Next
EndIf
Next
_GUICtrlTreeView_EndUpdate($hTreeView)
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()
回复 1# showshow
#include <GUIConstantsEx.au3>
#include <GuiTreeView.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <File.au3>
;~ #include <Array.au3>
$Debug_TV = False ; Check ClassName being passed to functions, set to True and use a handle to another control to see it work
Local $hItem, $hTreeView
Local $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS)
GUICreate("TreeView Set Icon", 400, 500)
$hTreeView = GUICtrlCreateTreeView(2, 2, 396, 388, $iStyle, $WS_EX_CLIENTEDGE)
GUISetState()
_GUICtrlTreeView_BeginUpdate($hTreeView)
_FindFile('c:')
_GUICtrlTreeView_EndUpdate($hTreeView)
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()
Func _FindFile($sPath)
$aFileList = _FileListToArray($sPath)
If Not @error Then
For $i = 1 To $aFileList - 1
$tm = GUICtrlCreateTreeViewItem($aFileList[$i], $hTreeView)
If StringInStr(FileGetAttrib($sPath & '\' & $aFileList[$i]), "D") Then
$DDD = _FileListToArray($sPath & '\' & $aFileList[$i])
If Not @error Then
For $s = 1 To $DDD - 1
$m = GUICtrlCreateTreeViewItem($DDD[$s], $tm)
Next
EndIf
EndIf
Next
EndIf
EndFunc ;==>_FindFile
应该点击一层搜索一层再展开,用_FileListToArray() 即可。 回复 3# afan
我也是这么想的~
给个例子让楼主自己想{:face (303):} 用_FileListToArray() 即可
页:
[1]