找回密码
 加入
搜索
查看: 3742|回复: 4

[GUI管理] 通过TreeView 编写资源管理器,如何实现更高效!

[复制链接]
发表于 2012-2-24 15:13:37 | 显示全部楼层 |阅读模式
问题如标题
通过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[10], $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[0]
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[0]
For $x1 = 1 To $n1-1                
        $m=GUICtrlCreateTreeViewItem($cow1[$x1], $tm)
Next
        EndIf

        Next
        _GUICtrlTreeView_EndUpdate($hTreeView)

        Do
        Until GUIGetMsg() = $GUI_EVENT_CLOSE
        GUIDelete()
发表于 2012-2-24 17:28:03 | 显示全部楼层
回复 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[10], $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[0] - 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[0] - 1
                                                $m = GUICtrlCreateTreeViewItem($DDD[$s], $tm)
                                        Next
                                EndIf
                        EndIf
                Next
        EndIf
EndFunc   ;==>_FindFile

评分

参与人数 1金钱 +20 收起 理由
afan + 20

查看全部评分

发表于 2012-2-24 17:32:12 | 显示全部楼层
应该点击一层搜索一层再展开,用_FileListToArray() 即可。
发表于 2012-2-24 17:34:53 | 显示全部楼层
回复 3# afan

我也是这么想的~
给个例子让楼主自己想
发表于 2012-3-5 15:00:23 | 显示全部楼层
用_FileListToArray() 即可
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-19 17:29 , Processed in 0.097466 second(s), 28 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表