找回密码
 加入
搜索
查看: 12346|回复: 20

[GUI管理] 如何将一个ini标准文件,以树形显示出来?

 火.. [复制链接]
发表于 2011-7-14 18:00:50 | 显示全部楼层 |阅读模式
悬赏500金钱已解决
如题,求解

最佳答案

查看完整内容

回复 9# netegg 就是: ini 文件可以分为几个 Section,每个 Section 的名称用 [] 括起来,在一个 Section 中,可以有很多的 Key,每一个 Key 可以有一个值并占用一行,格式是 Key=value 如,若一个key占多行等等就不是标准的了…… 若要显示值: [au3] #NoTrayIcon #include Opt("GUIOnEventMode", 1) Local $INIFile = @ScriptDir & "\zh-CN.ini" if not FileExists($INIFile) then msgbox(16, "Error", "Cannot f ...
发表于 2011-7-14 18:00:51 | 显示全部楼层
回复 9# netegg


    就是:
ini 文件可以分为几个 Section,每个 Section 的名称用 [] 括起来,在一个 Section 中,可以有很多的 Key,每一个 Key 可以有一个值并占用一行,格式是 Key=value

如,若一个key占多行等等就不是标准的了……

若要显示值:

#NoTrayIcon
#include <GuiConstants.au3>

Opt("GUIOnEventMode", 1)
Local $INIFile = @ScriptDir & "\zh-CN.ini"

if not FileExists($INIFile) then 
        msgbox(16, "Error", "Cannot find INI file",5)
        Exit
EndIf

$Form1 = GUICreate("Example", 300, 500)
GUISetOnEvent($GUI_EVENT_CLOSE, "Event")

$TreeView = GUICtrlCreateTreeView(10, 10, 200, 450)
GUICtrlSetOnEvent(-1, "Event")

$SectionName = IniReadSectionNames($INIFile)
If IsArray($SectionName) Then
        Local $Item[$SectionName[0] + 1]
        For $i = 1 To $SectionName[0]
                $Item[$i] = GUICtrlCreateTreeViewItem($SectionName[$i], $TreeView)
                $IniSection = IniReadSection($INIFile, $SectionName[$i])
                if not @error Then
                        For $j = 1 To $IniSection[0][0]
                                GUICtrlCreateTreeViewItem($IniSection[$j][0], $Item[$i])
                                GUICtrlCreateTreeViewItem($IniSection[$j][1], -1)
                                GUICtrlSetOnEvent(-1, "Event")
                        Next
                EndIf
        Next
EndIf

GUISetState()

 
While True
        Sleep(100)
WEnd


Func Event()
   Switch @GUI_CtrlId
      Case $GUI_EVENT_CLOSE
         Exit
      Case Else
         $Val = GUICtrlRead(@GUI_CtrlId,1)
                 ;......
   EndSwitch
EndFunc




本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2011-7-14 20:07:41 | 显示全部楼层
老板说话,也说得不明不白的:如何个树形法?
 楼主| 发表于 2011-7-14 20:47:54 | 显示全部楼层
回复 2# happytc


    呵呵,那是你不理解,,, #include <GuiTreeView.au3>就行
发表于 2011-7-14 20:59:44 | 显示全部楼层
回复  happytc


    呵呵,那是你不理解,,, #include 就行
kn007 发表于 2011-7-14 20:47


这个我知道了
我不理解的是你要怎么个“显示”法?
 楼主| 发表于 2011-7-14 21:02:21 | 显示全部楼层
这个我知道了
我不理解的是你要怎么个“显示”法?
happytc 发表于 2011-7-14 20:59



    就是list出来啊。。。。我就问怎么实现啊,还反问,我可不认为难理解。。。
发表于 2011-7-14 21:37:04 | 显示全部楼层
本帖最后由 happytc 于 2011-7-14 22:00 编辑

回复 5# kn007


    其实还是不大理解你的需求,如下面的例子,是这样吗?如是这样,也太简单了,不象是老板问的问题呀

#NoTrayIcon
#include <GuiConstants.au3>

Opt("GUIOnEventMode", 1)
Local $INIFile = @ScriptDir & "\zh-CN.ini"

if not FileExists($INIFile) then 
        msgbox(16, "Error", "Cannot find INI file",5)
        Exit
EndIf

$Form1 = GUICreate("Example", 300, 500)
GUISetOnEvent($GUI_EVENT_CLOSE, "Event")

$TreeView = GUICtrlCreateTreeView(10, 10, 200, 450)
GUICtrlSetOnEvent(-1, "Event")

$SectionName = IniReadSectionNames($INIFile)
If IsArray($SectionName) Then
        Local $Item[$SectionName[0] + 1]
        For $i = 1 To $SectionName[0]
                $Item[$i] = GUICtrlCreateTreeViewItem($SectionName[$i], $TreeView)
                $IniSection = IniReadSection($INIFile, $SectionName[$i])
                if not @error Then
                        For $j = 1 To $IniSection[0][0]
                                GUICtrlCreateTreeViewItem($IniSection[$j][0], $Item[$i])
                                GUICtrlSetOnEvent(-1, "Event")
                        Next
                EndIf
        Next
EndIf

GUISetState()

 
While True
        Sleep(100)
WEnd


Func Event()
   Switch @GUI_CtrlId
      Case $GUI_EVENT_CLOSE
         Exit
      Case Else
         $Val = GUICtrlRead(@GUI_CtrlId,1)
                 ;......
   EndSwitch
EndFunc

其中的zh-CN.ini文件在下面下载(或者你自己随便建个INi)
http://www.autoitx.com/thread-25502-1-2.html

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×

评分

参与人数 1威望 +2 金钱 +60 贡献 +10 收起 理由
kn007 + 2 + 60 + 10 很感谢你。可能因为你的逻辑性比较好,所以 ...

查看全部评分

发表于 2011-7-14 22:07:30 | 显示全部楼层
本帖最后由 netegg 于 2011-7-14 22:11 编辑

回复 6# happytc

ini至少是三层树,你这个似乎有些欠妥,大概应该是
     [item]
         |
         |
         -value
              |
              |
              -data
上面加section的话再多一层
发表于 2011-7-14 22:11:53 | 显示全部楼层
回复 7# netegg


    一楼说的是:标准的Ini文件

你的意思是说把设置的值也显示出来?若是这样也容易呀,再加一行就可以了
反正IniReadSection数组里已经存了“关键字”和其对应的数值.
发表于 2011-7-14 22:12:53 | 显示全部楼层
回复 8# happytc

标准的ini文件是什么样?请指教
 楼主| 发表于 2011-7-14 22:27:07 | 显示全部楼层
回复  happytc

标准的ini文件是什么样?请指教
netegg 发表于 2011-7-14 22:12



    就如你刚才所说的。集合、键名、键值
 楼主| 发表于 2011-7-14 22:30:41 | 显示全部楼层
回复  kn007


    其实还是不大理解你的需求,如下面的例子,是这样吗?如是这样,也太简单了,不象是 ...
happytc 发表于 2011-7-14 21:37



    很感谢你。可能因为你的逻辑性比较好,所以问得比较详细。但我问的一般建立在help的用语基础上。这段代码也可以帮到我,我之前弄了之后,总是因为读取到乱码而失败。从你的代码,我发现了原因了。受教了。
发表于 2011-7-14 22:31:50 | 显示全部楼层
如上面的文件,就是标准的Ini文件
[Common]
OK=确定
Cancel=取消
.....
发表于 2011-7-14 22:51:00 | 显示全部楼层
很感谢你。可能因为你的逻辑性比较好,所以问得比较详细。但我问的一般建立在help的用语基础上。这段代码也可以帮到我,我之前弄了之后,总是因为读取到乱码而失败。
kn007 发表于 2011-7-14 22:30

怎么可能读取出乱码呢?
表示无法理解
 楼主| 发表于 2011-7-14 22:51:09 | 显示全部楼层
回复  kn007


    其实还是不大理解你的需求,如下面的例子,是这样吗?如是这样,也太简单了,不象是 ...
happytc 发表于 2011-7-14 21:37



    怎么读取选定的项目?

利用
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR
    $hWndTreeView = GUICtrlGetHandle($TreeView)
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndTreeView
            Switch $iCode
                Case -451
                    $item = _GUICtrlTreeView_GetSelection($hWndTreeView)
                    $root = $item
                    If _GUICtrlTreeView_GetChildCount($hWndTreeView,$item) <= 0 Then
                        $txt = _GUICtrlTreeView_GetText($hWndTreeView,$item)
                        ConsoleWrite($txt&@CRLF)
                    EndIf
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc
总是得到乱码,选了3样,得到如下

山楂汁冰淇淋
陘???謨?坚果冰淇淋
??兰香子冰淇淋
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-10 04:35 , Processed in 0.084969 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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