找回密码
 加入
搜索
查看: 7196|回复: 10

[系统综合] 请教一个问题,有关于TreeView到ListBox的问题[已解决]

  [复制链接]
发表于 2010-4-25 21:53:34 | 显示全部楼层 |阅读模式
本帖最后由 jonyzhr 于 2010-5-9 19:05 编辑
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
#Include <GuiListBox.au3>
#include <GuiTreeView.au3>
#Region ### START Koda GUI section ### Form=e:\jonyau3\移动实用工具\彩铃设置.kxf
$Form1 = GUICreate("彩铃设置工具", 733, 512, -1, -1)
$Group1 = GUICtrlCreateGroup("", 8, 0, 721, 505, -1, $WS_EX_TRANSPARENT)
$Tab1 = GUICtrlCreateTab(16, 8, 697, 457)
GUICtrlSetResizing(-1, $GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
$TabSheet1 = GUICtrlCreateTabItem("开始菜单桌面类")
$Group2 = GUICtrlCreateGroup("显示选项", 24, 40, 369, 273)
$Group3 = GUICtrlCreateGroup("全部选项", 32, 56, 169, 249)
$TvStrat = GUICtrlCreateTreeView(37, 72, 158, 225, BitOR($TVS_HASBUTTONS,$TVS_HASLINES,$TVS_LINESATROOT,$TVS_DISABLEDRAGDROP,$TVS_SHOWSELALWAYS,$TVS_CHECKBOXES,$WS_GROUP,$WS_TABSTOP))
$TvStrat_0 = GUICtrlCreateTreeViewItem("程序列表类", $TvStrat)
$TvStrat_1 = GUICtrlCreateTreeViewItem("附加的程序列表", $TvStrat_0)
$TvStrat_2 = GUICtrlCreateTreeViewItem("常用程序列表", $TvStrat_0)
$TvStrat_3 = GUICtrlCreateTreeViewItem("更多程序列表", $TvStrat_0)
$TvStrat_4 = GUICtrlCreateTreeViewItem("公用程序列表", $TvStrat_0)
$TvStrat_5 = GUICtrlCreateTreeViewItem("Windows Update 链接", $TvStrat)
$TvStrat_6 = GUICtrlCreateTreeViewItem("用户文件夹类", $TvStrat)
$TvStrat_7 = GUICtrlCreateTreeViewItem("我的文档", $TvStrat_6)
$TvStrat_8 = GUICtrlCreateTreeViewItem("图片收藏", $TvStrat_6)
$TvStrat_9 = GUICtrlCreateTreeViewItem("我的音乐", $TvStrat_6)
$TvStrat_10 = GUICtrlCreateTreeViewItem("最近使用的文档", $TvStrat_6)
$TvStrat_11 = GUICtrlCreateTreeViewItem("我的电脑", $TvStrat_6)
$TvStrat_12 = GUICtrlCreateTreeViewItem("网上邻居", $TvStrat_6)
$TvStrat_13 = GUICtrlCreateTreeViewItem("用户名", $TvStrat_6)
$TvStrat_14 = GUICtrlCreateTreeViewItem("系统应用类", $TvStrat)
$TvStrat_15 = GUICtrlCreateTreeViewItem("控制面板", $TvStrat_14)
$TvStrat_16 = GUICtrlCreateTreeViewItem("网络连接", $TvStrat_14)
$TvStrat_17 = GUICtrlCreateTreeViewItem("打印机传真", $TvStrat_14)
GUICtrlSetState (-1,$GUI_CHECKED)
$TvStrat_18 = GUICtrlCreateTreeViewItem("其他类", $TvStrat)
$TvStrat_19 = GUICtrlCreateTreeViewItem("帮助", $TvStrat_18)
$TvStrat_20 = GUICtrlCreateTreeViewItem("搜索", $TvStrat_18)
$TvStrat_21 = GUICtrlCreateTreeViewItem("运行", $TvStrat_18)
$TvStrat_22 = GUICtrlCreateTreeViewItem("注销", $TvStrat_18)
$TvStrat_23 = GUICtrlCreateTreeViewItem("关闭计算机", $TvStrat_18)
$TvStrat_24 = GUICtrlCreateTreeViewItem("设定程序访问和默认值", $TvStrat_18)
$TvStrat_25 = GUICtrlCreateTreeViewItem("开始菜单右键(禁止)", $TvStrat_18)
$TvStrat_26 = GUICtrlCreateTreeViewItem("任务栏右键(禁止)", $TvStrat_18)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group4 = GUICtrlCreateGroup("显示启用选项", 208, 56, 177, 217)
$LsStrat = GUICtrlCreateList("", 216, 72, 161, 188)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$BtnStrat = GUICtrlCreateButton("应用", 280, 280, 75, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group14 = GUICtrlCreateGroup("桌面系统图标", 399, 38, 305, 273)
$Group15 = GUICtrlCreateGroup("全部默认图标", 407, 54, 137, 249)
$TvDesktop = GUICtrlCreateTreeView(412, 70, 126, 225, BitOR($TVS_HASBUTTONS,$TVS_HASLINES,$TVS_LINESATROOT,$TVS_DISABLEDRAGDROP,$TVS_SHOWSELALWAYS,$TVS_CHECKBOXES,$WS_GROUP,$WS_TABSTOP))
$TvDesktop_0 = GUICtrlCreateTreeViewItem("系统图标类", $TvDesktop)
$TvDesktop_1 = GUICtrlCreateTreeViewItem("我的文档", $TvDesktop_0)
$TvDesktop_2 = GUICtrlCreateTreeViewItem("我的电脑", $TvDesktop_0)
$TvDesktop_3 = GUICtrlCreateTreeViewItem("网上邻居", $TvDesktop_0)
$TvDesktop_4 = GUICtrlCreateTreeViewItem("Internet Explorer", $TvDesktop_0)
$TvDesktop_5 = GUICtrlCreateTreeViewItem("回收站", $TvDesktop_0)
$TvDesktop_6 = GUICtrlCreateTreeViewItem("Windows Mider", $TvDesktop_0)
$TvDesktop_7 = GUICtrlCreateTreeViewItem("桌面鼠标右键(禁用)", $TvDesktop)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group16 = GUICtrlCreateGroup("显示图标", 551, 54, 145, 217)
$LsDesktop = GUICtrlCreateList("", 560, 72, 129, 188)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$BtnDesktop = GUICtrlCreateButton("应 用", 599, 278, 75, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group18 = GUICtrlCreateGroup("说明", 24, 320, 681, 137)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$TabSheet2 = GUICtrlCreateTabItem("IE设置类")
$Group5 = GUICtrlCreateGroup("IE标准按钮", 24, 32, 329, 273)
$Group6 = GUICtrlCreateGroup("全部按钮", 32, 48, 153, 249)
$TvIE = GUICtrlCreateTreeView(37, 64, 142, 225, BitOR($TVS_HASBUTTONS,$TVS_HASLINES,$TVS_LINESATROOT,$TVS_DISABLEDRAGDROP,$TVS_SHOWSELALWAYS,$TVS_CHECKBOXES,$WS_GROUP,$WS_TABSTOP))
$TvIE_0 = GUICtrlCreateTreeViewItem("标准按钮类", $TvIE)
$TvIE_1 = GUICtrlCreateTreeViewItem("后退", $TvIE_0)
$TvIE_2 = GUICtrlCreateTreeViewItem("前进", $TvIE_0)
$TvIE_3 = GUICtrlCreateTreeViewItem("停止", $TvIE_0)
$TvIE_4 = GUICtrlCreateTreeViewItem("刷新", $TvIE_0)
$TvIE_5 = GUICtrlCreateTreeViewItem("主页", $TvIE_0)
$TvIE_6 = GUICtrlCreateTreeViewItem("搜索", $TvIE_0)
$TvIE_7 = GUICtrlCreateTreeViewItem("文件夹", $TvIE_0)
$TvIE_8 = GUICtrlCreateTreeViewItem("收藏夹", $TvIE_0)
$TvIE_9 = GUICtrlCreateTreeViewItem("多媒体", $TvIE_0)
$TvIE_10 = GUICtrlCreateTreeViewItem("历史", $TvIE_0)
$TvIE_11 = GUICtrlCreateTreeViewItem("全屏", $TvIE_0)
$TvIE_12 = GUICtrlCreateTreeViewItem("工具", $TvIE_0)
$TvIE_13 = GUICtrlCreateTreeViewItem("邮件", $TvIE_0)
$TvIE_14 = GUICtrlCreateTreeViewItem("字体", $TvIE_0)
$TvIE_15 = GUICtrlCreateTreeViewItem("打印", $TvIE_0)
$TvIE_16 = GUICtrlCreateTreeViewItem("编辑", $TvIE_0)
$TvIE_17 = GUICtrlCreateTreeViewItem("讨论", $TvIE_0)
$TvIE_18 = GUICtrlCreateTreeViewItem("剪切", $TvIE_0)
$TvIE_19 = GUICtrlCreateTreeViewItem("复制", $TvIE_0)
$TvIE_20 = GUICtrlCreateTreeViewItem("粘贴", $TvIE_0)
$TvIE_21 = GUICtrlCreateTreeViewItem("编码", $TvIE_0)
$TvIE_22 = GUICtrlCreateTreeViewItem("打印预览", $TvIE_0)
$TvIE_23 = GUICtrlCreateTreeViewItem("工具栏类", $TvIE)
$TvIE_24 = GUICtrlCreateTreeViewItem("自定义按钮(删除)", $TvIE_23)
$TvIE_25 = GUICtrlCreateTreeViewItem("锁定工具栏", $TvIE_23)
$TvIE_26 = GUICtrlCreateTreeViewItem("菜单栏(删除)", $TvIE)
$TvIE_27 = GUICtrlCreateTreeViewItem("地址栏(删除)", $TvIE)
$TvIE_28 = GUICtrlCreateTreeViewItem("鼠标右键(禁止)", $TvIE)
$TvIE_29 = GUICtrlCreateTreeViewItem("安全选项", $TvIE)
$TvIE_30 = GUICtrlCreateTreeViewItem("Internet(启动)", $TvIE_29)
$TvIE_31 = GUICtrlCreateTreeViewItem("本地Internet(启动)", $TvIE_29)
$TvIE_32 = GUICtrlCreateTreeViewItem("受信任站点(启动)", $TvIE_29)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group7 = GUICtrlCreateGroup("显示按钮", 192, 48, 153, 217)
$LsIE = GUICtrlCreateList("", 200, 64, 137, 188)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$BtnIE = GUICtrlCreateButton("应 用", 232, 272, 75, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group8 = GUICtrlCreateGroup("网站设置", 360, 32, 345, 273)
$CobBelong = GUICtrlCreateCombo("", 608, 56, 89, 25)
GUICtrlSetData(-1, "主页|桌面|收藏夹|受信任站点|隐私站点|代理例外|代理服务器", "主页")
$InpWWW = GUICtrlCreateInput("InpWWW", 391, 56, 105, 21)
$Label1 = GUICtrlCreateLabel("网址", 363, 60, 28, 17)
$Label2 = GUICtrlCreateLabel("名字", 498, 60, 28, 17)
$InpName = GUICtrlCreateInput("InpName", 524, 56, 73, 21)
$LvWWW = GUICtrlCreateListView("|网址|名字|属于", 368, 88, 274, 206, -1, BitOR($WS_EX_CLIENTEDGE,$LVS_EX_GRIDLINES,$LVS_EX_FULLROWSELECT))
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 20)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 100)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 70)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 3, 80)
$BtnWWWAdd = GUICtrlCreateButton("增加", 648, 104, 51, 25)
$BtnWWWDel = GUICtrlCreateButton("删除", 648, 144, 51, 25)
$BtnWWW = GUICtrlCreateButton("应用", 648, 256, 51, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group9 = GUICtrlCreateGroup("辅助设置", 24, 312, 681, 145)
$Group10 = GUICtrlCreateGroup("阻止弹出窗口", 32, 328, 89, 121)
$RdNoStop = GUICtrlCreateRadio("不阻止", 40, 352, 65, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$RdStop = GUICtrlCreateRadio("阻止", 40, 384, 57, 17)
$BtnStop = GUICtrlCreateButton("设置", 48, 416, 51, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group11 = GUICtrlCreateGroup("代理服务器", 128, 328, 81, 121)
$RdNoProxy = GUICtrlCreateRadio("不启用", 136, 352, 57, 17)
$RdProxy = GUICtrlCreateRadio("启用", 136, 384, 49, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$BtnProxy = GUICtrlCreateButton("设置", 144, 416, 51, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group12 = GUICtrlCreateGroup("本地不用代理", 216, 328, 89, 121)
$RdNoLocalProxy = GUICtrlCreateRadio("不启用", 232, 352, 65, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$RdLocalProxy = GUICtrlCreateRadio("启用", 232, 384, 57, 17)
$BtnLocalProxy = GUICtrlCreateButton("设置", 232, 416, 51, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group13 = GUICtrlCreateGroup("Windows防火墙", 312, 328, 97, 121)
$RdCloseFirewall = GUICtrlCreateRadio("彻底关闭", 328, 352, 73, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$RdFirewall = GUICtrlCreateRadio("开启", 328, 384, 65, 17)
$BtnFirewall = GUICtrlCreateButton("设置", 336, 416, 51, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group17 = GUICtrlCreateGroup("任务管理器", 416, 328, 81, 121)
$RdStopTask = GUICtrlCreateRadio("禁用", 432, 352, 49, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$RdTask = GUICtrlCreateRadio("启用", 432, 384, 49, 17)
$BtnTask = GUICtrlCreateButton("设置", 432, 416, 51, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateTabItem("")
$BtnOneKeySet = GUICtrlCreateButton("一键设置", 592, 472, 91, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

While 1        
        _TreeViewToListBox($TvStrat,$LsStrat)
        $nMsg = GUIGetMsg()        
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        GUIDelete($Form1)                        
                        Exit
                Case $BtnOneKeySet
                        
                        MsgBox("","",ControlGetFocus("彩铃设置工具"))
                        
        EndSwitch

WEnd

Func _TreeViewToListBox($TreeView,$ListBox)        
;说明   
;     能把TreeView中复选框选中的项目显示到指定的ListBox中

;参数
;                $TreeView -----TreeView句柄
;                $ListBox -----ListBox句柄
        Local $TVItemString = "" ;获取TreeView中选择的Text
        Local $LsIndex        ;ListBox的项目数量
        Local $TVSubItemString = _GUICtrlTreeView_GetFirstItem($TreeView) ;获取TreeView中第一个项目的句柄
        Local $TreeViewIndexs = _GUICtrlTreeView_GetCount($TreeView) ;获取TreeView中项目的数量                
        For $i = 0 To $TreeViewIndexs-1        ;循环项目数量                        
                        If _GUICtrlTreeView_GetChecked($TreeView, $TVSubItemString) = True Then ;如果TreeView该项目的复选框被选择
                                $TVItemString = _GUICtrlTreeView_GetText($TreeView, $TVSubItemString) ;获取TreeView被选择的项目的文本        
                                If _GUICtrlListBox_FindInText($ListBox,$TVItemString) = -1 Then
                                        _GUICtrlListBox_AddString($ListBox,$TVItemString)                                        
                                EndIf
                        Else ;如果该项目的复选框不被选择
                                $TVItemString = _GUICtrlTreeView_GetText($TreeView, $TVSubItemString) ;获取TreeView该项目的文本
                                If _GUICtrlListBox_FindInText($ListBox,$TVItemString) <> -1 Then
                                        _GUICtrlListBox_DeleteString($ListBox,_GUICtrlListBox_FindInText($ListBox,$TVItemString)) ;删除掉存在的字符串                                        
                                EndIf
                        EndIf
                                $TVSubItemString = _GUICtrlTreeView_GetNext($TreeView,$TVSubItemString)        ;吧TreeView句柄移至下一个
                Next                
EndFunc
以上代码当TreeView中勾选太多的时候,在关闭程序时候会卡好久没关成,请各位高手帮看看,要达到这样的效果还有更好的方法么?还有什么原因造成的,如果使用该函数应该处理才能立即关闭?

注:#10的方法挺不错,正解
发表于 2010-4-25 22:40:08 | 显示全部楼层
我拿你的代码在我这测试很正常,。。
 楼主| 发表于 2010-4-26 09:08:03 | 显示全部楼层
是在勾选太多的选项的时候退出会变卡,如果没有勾到的话是不会卡
发表于 2010-4-26 13:26:14 | 显示全部楼层
不勾选 的话。 。 我看了一下CPU占用 。。 已经到 30%
我这里的CPU是 E5400
 楼主| 发表于 2010-4-28 15:07:04 | 显示全部楼层
有人有办法么,请指教
发表于 2010-4-28 19:42:49 | 显示全部楼层
不能把_TreeViewToListBox($TvStrat,$LsStrat)放在While 1和WEnd中间。你这样会每250毫秒执行一次函数,而不管使用者有无进行点击。CPU使用率当然很高。而当treeview中有多项被选中时,每250毫秒会在listbox中显示一次,重复显示。只是因为太快,你看不出其闪烁而已。不卡才怪呢。
思路不应这样,从TREEVIEW到LISTBOX,论坛已有好多例子有成熟的解决方案。要利用事件功能。
还有楼主好象不知道有 数组变量 这一说吗?
 楼主| 发表于 2010-5-2 20:50:32 | 显示全部楼层
如果这个思路不对,请问该如何找思路,冒昧本人愚笨不懂事件
发表于 2010-5-2 21:05:51 | 显示全部楼层
大概看了看,貌似主要问题是那个自定义函数放在循环里有些不对,每次都要重新读吗
 楼主| 发表于 2010-5-4 09:01:56 | 显示全部楼层
回复 8# netegg

想过把自定义函数放到鼠标单击事件里,但貌似在单击按下的时候就已经执行了,都没等Item选择,再次单击才会执行上次的结果,所以纳闷
发表于 2010-5-5 12:41:19 | 显示全部楼层
本帖最后由 shqf 于 2010-5-5 12:44 编辑
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListBox.au3>
#include <GuiTreeView.au3>

#Include <Array.au3>

#Region ### START Koda GUI section ### Form=e:\jonyau3\移动实用工具\彩铃设置.kxf
$Form1 = GUICreate("彩铃设置工具", 733, 512, -1, -1)
$Group1 = GUICtrlCreateGroup("", 8, 0, 721, 505, -1, $WS_EX_TRANSPARENT)
$Tab1 = GUICtrlCreateTab(16, 8, 697, 457)
GUICtrlSetResizing(-1, $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
$TabSheet1 = GUICtrlCreateTabItem("开始菜单桌面类")
$Group2 = GUICtrlCreateGroup("显示选项", 24, 40, 369, 273)
$Group3 = GUICtrlCreateGroup("全部选项", 32, 56, 169, 249)
$TvStrat = GUICtrlCreateTreeView(37, 72, 158, 225, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES, $WS_GROUP, $WS_TABSTOP))


Dim $Father[1], $Son[1],$Number
Dim $FatherArray[6] = [5, "程序列表类", "Windows Update 链接", "用户文件夹类", "系统应用类", "其他类"]
Dim $SonArray[5][10] = [[4, "附加的程序列表", "常用程序列表", "更多程序列表", "公用程序列表"],[1, "Windows Update 链接"], _
                [7, "我的文档", "图片收藏", "我的音乐", "最近使用的文档", "我的电脑", "网上邻居", "用户名"],[3, "控制面板", _
                "网络连接", "打印机传真"],[8, "帮助", "搜索", "运行", "注销", "关闭计算机", "设定程序访问和默认值", "开始菜单右键(禁止)", "任务栏右键(禁止)"]]
For $i = 1 To 5
        $hFatherItem = GUICtrlCreateTreeViewItem($FatherArray[$i], $TvStrat)
        _ArrayAdd($Father, $hFatherItem)
        For $j = 1 To $SonArray[$i - 1][0]
                $hSonItem = GUICtrlCreateTreeViewItem($SonArray[$i-1][$j], $hFatherItem)
                _ArrayAdd($Son, $hSonItem)                
        Next
Next
GUICtrlCreateGroup("", -99, -99, 1, 1)


$Group4 = GUICtrlCreateGroup("显示启用选项", 208, 56, 177, 217)
$LsStrat = GUICtrlCreateList("", 216, 72, 161, 188)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$BtnStrat = GUICtrlCreateButton("应用", 280, 280, 75, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group14 = GUICtrlCreateGroup("桌面系统图标", 399, 38, 305, 273)
$Group15 = GUICtrlCreateGroup("全部默认图标", 407, 54, 137, 249)
$TvDesktop = GUICtrlCreateTreeView(412, 70, 126, 225, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES, $WS_GROUP, $WS_TABSTOP))
$TvDesktop_0 = GUICtrlCreateTreeViewItem("系统图标类", $TvDesktop)
$TvDesktop_1 = GUICtrlCreateTreeViewItem("我的文档", $TvDesktop_0)
$TvDesktop_2 = GUICtrlCreateTreeViewItem("我的电脑", $TvDesktop_0)
$TvDesktop_3 = GUICtrlCreateTreeViewItem("网上邻居", $TvDesktop_0)
$TvDesktop_4 = GUICtrlCreateTreeViewItem("Internet Explorer", $TvDesktop_0)
$TvDesktop_5 = GUICtrlCreateTreeViewItem("回收站", $TvDesktop_0)
$TvDesktop_6 = GUICtrlCreateTreeViewItem("Windows Mider", $TvDesktop_0)
$TvDesktop_7 = GUICtrlCreateTreeViewItem("桌面鼠标右键(禁用)", $TvDesktop)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group16 = GUICtrlCreateGroup("显示图标", 551, 54, 145, 217)
$LsDesktop = GUICtrlCreateList("", 560, 72, 129, 188)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$BtnDesktop = GUICtrlCreateButton("应 用", 599, 278, 75, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group18 = GUICtrlCreateGroup("说明", 24, 320, 681, 137)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$TabSheet2 = GUICtrlCreateTabItem("IE设置类")
$Group5 = GUICtrlCreateGroup("IE标准按钮", 24, 32, 329, 273)
$Group6 = GUICtrlCreateGroup("全部按钮", 32, 48, 153, 249)
$TvIE = GUICtrlCreateTreeView(37, 64, 142, 225, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES, $WS_GROUP, $WS_TABSTOP))
$TvIE_0 = GUICtrlCreateTreeViewItem("标准按钮类", $TvIE)
$TvIE_1 = GUICtrlCreateTreeViewItem("后退", $TvIE_0)
$TvIE_2 = GUICtrlCreateTreeViewItem("前进", $TvIE_0)
$TvIE_3 = GUICtrlCreateTreeViewItem("停止", $TvIE_0)
$TvIE_4 = GUICtrlCreateTreeViewItem("刷新", $TvIE_0)
$TvIE_5 = GUICtrlCreateTreeViewItem("主页", $TvIE_0)
$TvIE_6 = GUICtrlCreateTreeViewItem("搜索", $TvIE_0)
$TvIE_7 = GUICtrlCreateTreeViewItem("文件夹", $TvIE_0)
$TvIE_8 = GUICtrlCreateTreeViewItem("收藏夹", $TvIE_0)
$TvIE_9 = GUICtrlCreateTreeViewItem("多媒体", $TvIE_0)
$TvIE_10 = GUICtrlCreateTreeViewItem("历史", $TvIE_0)
$TvIE_11 = GUICtrlCreateTreeViewItem("全屏", $TvIE_0)
$TvIE_12 = GUICtrlCreateTreeViewItem("工具", $TvIE_0)
$TvIE_13 = GUICtrlCreateTreeViewItem("邮件", $TvIE_0)
$TvIE_14 = GUICtrlCreateTreeViewItem("字体", $TvIE_0)
$TvIE_15 = GUICtrlCreateTreeViewItem("打印", $TvIE_0)
$TvIE_16 = GUICtrlCreateTreeViewItem("编辑", $TvIE_0)
$TvIE_17 = GUICtrlCreateTreeViewItem("讨论", $TvIE_0)
$TvIE_18 = GUICtrlCreateTreeViewItem("剪切", $TvIE_0)
$TvIE_19 = GUICtrlCreateTreeViewItem("复制", $TvIE_0)
$TvIE_20 = GUICtrlCreateTreeViewItem("粘贴", $TvIE_0)
$TvIE_21 = GUICtrlCreateTreeViewItem("编码", $TvIE_0)
$TvIE_22 = GUICtrlCreateTreeViewItem("打印预览", $TvIE_0)
$TvIE_23 = GUICtrlCreateTreeViewItem("工具栏类", $TvIE)
$TvIE_24 = GUICtrlCreateTreeViewItem("自定义按钮(删除)", $TvIE_23)
$TvIE_25 = GUICtrlCreateTreeViewItem("锁定工具栏", $TvIE_23)
$TvIE_26 = GUICtrlCreateTreeViewItem("菜单栏(删除)", $TvIE)
$TvIE_27 = GUICtrlCreateTreeViewItem("地址栏(删除)", $TvIE)
$TvIE_28 = GUICtrlCreateTreeViewItem("鼠标右键(禁止)", $TvIE)
$TvIE_29 = GUICtrlCreateTreeViewItem("安全选项", $TvIE)
$TvIE_30 = GUICtrlCreateTreeViewItem("Internet(启动)", $TvIE_29)
$TvIE_31 = GUICtrlCreateTreeViewItem("本地Internet(启动)", $TvIE_29)
$TvIE_32 = GUICtrlCreateTreeViewItem("受信任站点(启动)", $TvIE_29)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group7 = GUICtrlCreateGroup("显示按钮", 192, 48, 153, 217)
$LsIE = GUICtrlCreateList("", 200, 64, 137, 188)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$BtnIE = GUICtrlCreateButton("应 用", 232, 272, 75, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group8 = GUICtrlCreateGroup("网站设置", 360, 32, 345, 273)
$CobBelong = GUICtrlCreateCombo("", 608, 56, 89, 25)
GUICtrlSetData(-1, "主页|桌面|收藏夹|受信任站点|隐私站点|代理例外|代理服务器", "主页")
$InpWWW = GUICtrlCreateInput("InpWWW", 391, 56, 105, 21)
$Label1 = GUICtrlCreateLabel("网址", 363, 60, 28, 17)
$Label2 = GUICtrlCreateLabel("名字", 498, 60, 28, 17)
$InpName = GUICtrlCreateInput("InpName", 524, 56, 73, 21)
$LvWWW = GUICtrlCreateListView("|网址|名字|属于", 368, 88, 274, 206, -1, BitOR($WS_EX_CLIENTEDGE, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 20)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 100)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 70)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 3, 80)
$BtnWWWAdd = GUICtrlCreateButton("增加", 648, 104, 51, 25)
$BtnWWWDel = GUICtrlCreateButton("删除", 648, 144, 51, 25)
$BtnWWW = GUICtrlCreateButton("应用", 648, 256, 51, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group9 = GUICtrlCreateGroup("辅助设置", 24, 312, 681, 145)
$Group10 = GUICtrlCreateGroup("阻止弹出窗口", 32, 328, 89, 121)
$RdNoStop = GUICtrlCreateRadio("不阻止", 40, 352, 65, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$RdStop = GUICtrlCreateRadio("阻止", 40, 384, 57, 17)
$BtnStop = GUICtrlCreateButton("设置", 48, 416, 51, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group11 = GUICtrlCreateGroup("代理服务器", 128, 328, 81, 121)
$RdNoProxy = GUICtrlCreateRadio("不启用", 136, 352, 57, 17)
$RdProxy = GUICtrlCreateRadio("启用", 136, 384, 49, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$BtnProxy = GUICtrlCreateButton("设置", 144, 416, 51, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group12 = GUICtrlCreateGroup("本地不用代理", 216, 328, 89, 121)
$RdNoLocalProxy = GUICtrlCreateRadio("不启用", 232, 352, 65, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$RdLocalProxy = GUICtrlCreateRadio("启用", 232, 384, 57, 17)
$BtnLocalProxy = GUICtrlCreateButton("设置", 232, 416, 51, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group13 = GUICtrlCreateGroup("Windows防火墙", 312, 328, 97, 121)
$RdCloseFirewall = GUICtrlCreateRadio("彻底关闭", 328, 352, 73, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$RdFirewall = GUICtrlCreateRadio("开启", 328, 384, 65, 17)
$BtnFirewall = GUICtrlCreateButton("设置", 336, 416, 51, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group17 = GUICtrlCreateGroup("任务管理器", 416, 328, 81, 121)
$RdStopTask = GUICtrlCreateRadio("禁用", 432, 352, 49, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$RdTask = GUICtrlCreateRadio("启用", 432, 384, 49, 17)
$BtnTask = GUICtrlCreateButton("设置", 432, 416, 51, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateTabItem("")
$BtnOneKeySet = GUICtrlCreateButton("一键设置", 592, 472, 91, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

While 1

        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        GUIDelete($Form1)
                        Exit
                Case $BtnOneKeySet
                        MsgBox("", "", ControlGetFocus("彩铃设置工具"))
                        
                Case $Father[1] To $Father[UBound($Father) - 1], $Son[1] To $Son[UBound($Son) - 1] 
                        For $i = 0 To UBound($Father) - 1 ;父项目操作
                                If $nMsg = $Father[$i] And BitAND(GUICtrlRead($Father[$i]), $GUI_CHECKED) Then

                                        $Number = Number(_GUICtrlTreeView_GetChildCount($TvStrat, $Father[$i])) ;全选
                                        For $m = $Father[$i] To $Father[$i] + $Number
                                                GUICtrlSetState($m, $GUI_CHECKED)
                                        Next
                                ElseIf $nMsg = $Father[$i] And BitAND(GUICtrlRead($Father[$i]), $GUI_UNCHECKED) Then ;反选
                                        $Number = Number(_GUICtrlTreeView_GetChildCount($TvStrat, $Father[$i]))
                                        For $n = $Father[$i] To $Father[$i] + $Number
                                                GUICtrlSetState($n, $GUI_UNCHECKED)
                                        Next
                                EndIf
                        Next

                        For $z = 0 To UBound($Son) - 1 ;子项目操作
                                If $nMsg = $Son[$z] And BitAND(GUICtrlRead($Son[$z]), $GUI_CHECKED) Then ;子项目勾选,父项目跟着勾选
                                        $Handle = _GUICtrlTreeView_GetParentParam($TvStrat, $Son[$z])
                                        GUICtrlSetState($Handle, $GUI_CHECKED)
                                ElseIf $nMsg = $Son[$z] And BitAND(GUICtrlRead($Son[$z]), $GUI_UNCHECKED) Then
                                        $Handle = _GUICtrlTreeView_GetParentParam($TvStrat, $Son[$z])
                                        $Number = Number(_GUICtrlTreeView_GetChildCount($TvStrat, $Handle))
                                        For $o = $Handle To $Handle + $Number
                                                If GUICtrlRead($o) = $GUI_CHECKED Then ExitLoop
                                                If $o = $Handle + $Number Then GUICtrlSetState($Handle, $GUI_UNCHECKED) ;子项目全部取消勾选,父项目也跟着取消勾选
                                        Next
                                EndIf
                        Next
                        _TreeViewToListBox($TvStrat, $LsStrat)
                        

        EndSwitch

WEnd

Func _TreeViewToListBox($TreeView, $ListBox)
        ;说明
        ;     能把TreeView中复选框选中的项目显示到指定的ListBox中

        ;参数
        ;                $TreeView -----TreeView句柄
        ;                $ListBox -----ListBox句柄
        Local $TVItemString = "" ;获取TreeView中选择的Text
        Local $LsIndex ;ListBox的项目数量
        Local $TVSubItemString = _GUICtrlTreeView_GetFirstItem($TreeView) ;获取TreeView中第一个项目的句柄
        Local $TreeViewIndexs = _GUICtrlTreeView_GetCount($TreeView) ;获取TreeView中项目的数量
        For $i = 0 To $TreeViewIndexs - 1 ;循环项目数量
                If _GUICtrlTreeView_GetChecked($TreeView, $TVSubItemString) = True Then ;如果TreeView该项目的复选框被选择
                        $TVItemString = _GUICtrlTreeView_GetText($TreeView, $TVSubItemString) ;获取TreeView被选择的项目的文本
                        If _GUICtrlListBox_FindInText($ListBox, $TVItemString) = -1 Then
                                _GUICtrlListBox_AddString($ListBox, $TVItemString)
                        EndIf
                Else ;如果该项目的复选框不被选择
                        $TVItemString = _GUICtrlTreeView_GetText($TreeView, $TVSubItemString) ;获取TreeView该项目的文本
                        If _GUICtrlListBox_FindInText($ListBox, $TVItemString) <> -1 Then
                                _GUICtrlListBox_DeleteString($ListBox, _GUICtrlListBox_FindInText($ListBox, $TVItemString)) ;删除掉存在的字符串
                        EndIf
                EndIf
                $TVSubItemString = _GUICtrlTreeView_GetNext($TreeView, $TVSubItemString) ;吧TreeView句柄移至下一个
        Next
EndFunc   ;==>_TreeViewToListBox

评分

参与人数 2金钱 +30 贡献 +5 收起 理由
jonyzhr + 10 + 5 非常感谢你的方法,很好,谢谢你的帮助
afan + 20

查看全部评分

发表于 2011-3-3 17:41:37 | 显示全部楼层
很好的代码,很好的优化
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-12-23 07:48 , Processed in 0.089929 second(s), 27 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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