找回密码
 加入
搜索
楼主: lfx99

[AU3基础] [已解决]:GUICtrlCreateTreeView 如何根据 TXT文件,创建类似资源管理器的GUI。

 火.. [复制链接]
 楼主| 发表于 2012-2-2 14:39:01 | 显示全部楼层
多谢版主帮助,慢慢消化去。呵呵
发表于 2012-2-3 11:26:32 | 显示全部楼层
#include <GUITreeView.au3>

$hGUI = GUICreate("Test", 400, 300)

$hTreeView = _GUICtrlTreeView_Create($hGUI, 5, 5, 390, 290, BitOR($TVS_HASLINES, $TVS_SHOWSELALWAYS, $TVS_HASBUTTONS, $TVS_LINESATROOT), 512)

$iTimer = TimerInit()
_AddTreeViewItem($hTreeView, @ScriptDir & "\Dirs.txt")

MsgBox(0, TimerDiff($iTimer), "")

_GUICtrlTreeView_Expand($hTreeView)

GUISetState()
While GUIGetMsg() + 3
WEnd

Func _AddTreeViewItem($hTreeView, $sFilePath)
        Local $hFile, $iLine, $sText, $aText, $sCurrent, $sParent

        $hFile = FileOpen($sFilePath)
        If $hFile < 1 Then Return SetError(1, 0, 0)

        While 1
                $iLine += 1
                $sText  = FileReadLine($hFile, $iLine)

                If @error Then ExitLoop

                $sCurrent = ""
                $sParent = ""
                $aText = StringSplit($sText, "\")

                For $i = 1 To $aText[0]
                        $sCurrent &= $aText[$i] & "\"

                        If Not IsDeclared($sCurrent) Then
                                Assign($sCurrent, _GUICtrlTreeView_AddChild($hTreeView, Eval($sParent), $aText[$i]))
                        EndIf

                        $sParent = $sCurrent
                Next
        WEnd
        FileClose($hFile)

        Return $iLine > 0
EndFunc        ;==>_AddTreeViewItem
 楼主| 发表于 2012-2-3 16:35:48 | 显示全部楼层
真是惭愧,对Afan版主的正则还在慢慢琢磨中,P版的几个‘变量与变量转换’就轻松搞定。另外:为何在最后line  46 :Return $iLine > 0 ,不甚理解。
发表于 2012-2-7 00:55:31 | 显示全部楼层
P版代码的思路太诡异了。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-30 23:28 , Processed in 0.076294 second(s), 14 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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