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

[AU3基础] 搞了几天都没搞好,窗体源码贴出来,请帮忙看看是怎么回事

[复制链接]
发表于 2011-10-4 22:18:55 | 显示全部楼层 |阅读模式
#include <Array.au3>
#include <GuiTreeView.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <GuiListView.au3>
#include <StaticConstants.au3>
#Include <ACN_MISC.au3>
#Include <File.au3>



;声明总的变量
Global $tab,$msg

;声明tab1所用的变量


Global $Tab1,$tab1_view[26],$tab1Label[25],$TreeView1,$tab1button1,$tab1button2,$tab1button3,$tab1button4,$tab1button5,$progressbar1,$i1,$s1,$t1=25,$m



;声明tab2所用的变量
Global $tab2,$tab2_view[13],$tab2Label[12],$TreeView2,$tab2button1,$tab2button2,$tab2button3,$tab2button4,$tab2button5,$progressbar2,$i2,$s2,$t2=12

Global $CookiesAddress,$TemplatesAddress,$RecentAddress,$CacheAddress,$PrintHoodAddress,$HistoryAddress,$DiskRecycle,$x,$iStyle,$tstyle

Global $dir_prefix, $dir_number,$cp_path,$path,$i,$file_number,$file_prefix
;定义风格
;定义树列表风格
$iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES)


$tstyle = BitOR($WS_EX_CLIENTEDGE,$LVS_NOSORTHEADER,$LVS_SHOWSELALWAYS,$WS_BORDER)



If WinExists("windows7封装辅助工具") Then
        MsgBox(32,"","程序已运行,请返回。")
        Exit
EndIf
win7tools()

Func win7tools()
        ;创建窗体
       
        GUICreate("windows7封装辅助工具",440,440,-1,-1,0x00C00000)  
        ;GUISetBkColor(0x00E0FFFF)
       
        ;设置字体
        GUISetFont(9, 300)
     
         $tab = GUICtrlCreateTab(10, 10, 420, 20)
     
         $progressbar1=GUICtrlCreateProgress (10, 365, 420,20)
         
        $Tab1 = GUICtrlCreateTabItem("系统减肥")
        $TreeView1 = GUICtrlCreateTreeView(10, 53, 420, 300, $iStyle, $WS_EX_CLIENTEDGE)
        $tab1button1=GUICtrlCreateButton("全选", 10, 400, 70, 20)
        $tab1button2=GUICtrlCreateButton("全不选", 80, 400, 70, 20)
    $tab1button3=GUICtrlCreateButton("默认", 150, 400, 70, 20)
    $tab1button4=GUICtrlCreateButton("清理", 290, 400, 70, 20)
        $tab1button5=GUICtrlCreateButton("退出", 360, 400, 70, 20)
   
   
       
         
                  
                $tab1_view[1]=GUICtrlCreateTreeViewItem("系统升级补丁备份文件",$TreeView1)
                $tab1_view[2]=GUICtrlCreateTreeViewItem("用户公用文件",$TreeView1)
                $tab1_view[3]=GUICtrlCreateTreeViewItem("系统自带壁纸和主题",$TreeView1)
                $tab1_view[4]=GUICtrlCreateTreeViewItem("不同语言启动界面",$TreeView1)
                $tab1_view[5]=GUICtrlCreateTreeViewItem("程序安装解压目录",$TreeView1)
                $tab1_view[6]=GUICtrlCreateTreeViewItem("不常用的输入法",$TreeView1)
                $tab1_view[7]=GUICtrlCreateTreeViewItem("系统帮助文件",$TreeView1)
                $tab1_view[8]=GUICtrlCreateTreeViewItem("系统测试记录文件",$TreeView1)
                $tab1_view[9]=GUICtrlCreateTreeViewItem("驱动精减",$TreeView1)
                $tab1_view[10]=GUICtrlCreateTreeViewItem("系统相关组件",$TreeView1)
                $tab1_view[11]=GUICtrlCreateTreeViewItem("Table PC组件",$tab1_view[10])
                $tab1_view[12]=GUICtrlCreateTreeViewItem("Windows自带游戏",$tab1_view[10])
                $tab1_view[13]=GUICtrlCreateTreeViewItem("DVD Maker",$tab1_view[10])
                $tab1_view[14]=GUICtrlCreateTreeViewItem("媒体中心",$tab1_view[10])
                $tab1_view[15]=GUICtrlCreateTreeViewItem("远程差分压缩",$tab1_view[10])
                $tab1_view[16]=GUICtrlCreateTreeViewItem("XPS相关组件",$tab1_view[10])
                $tab1_view[17]=GUICtrlCreateTreeViewItem("系统垃圾文件清理",$TreeView1)
                $tab1_view[18]=GUICtrlCreateTreeViewItem("回收站文件",$tab1_view[17])
                $tab1_view[19]=GUICtrlCreateTreeViewItem("临时目录文件",$tab1_view[17])
                $tab1_view[20]=GUICtrlCreateTreeViewItem("程序打开文件记录",$tab1_view[17])
                $tab1_view[21]=GUICtrlCreateTreeViewItem("索引文件记录",$tab1_view[17])
                $tab1_view[22]=GUICtrlCreateTreeViewItem("用户临时文件",$tab1_view[17])
                $tab1_view[23]=GUICtrlCreateTreeViewItem("IE临时文件",$tab1_view[17])
                $tab1_view[24]=GUICtrlCreateTreeViewItem("历史记录文件",$tab1_view[17])
                $tab1_view[25]=GUICtrlCreateTreeViewItem("Cookie文件",$tab1_view[17])
               
                ;用来展开列表
                GUICtrlSetState($tab1_view[10], $GUI_EXPAND)
                GUICtrlSetState($tab1_view[17], $GUI_EXPAND)
               
                ;运行默认选择
                 default_select1()  
                  
         $tab2=GUICtrlCreateTabItem("封装优化")
                $TreeView2 = GUICtrlCreateTreeView(10, 60, 420, 300, $iStyle,$WS_EX_CLIENTEDGE)
                $tab2_view[1]=GUICtrlCreateTreeViewItem("关闭系统休眠",$TreeView2)
                $tab2_view[2]=GUICtrlCreateTreeViewItem("关闭UAC",$TreeView2)
                $tab2_view[3]=GUICtrlCreateTreeViewItem("关闭错误报告",$TreeView2)
                $tab2_view[4]=GUICtrlCreateTreeViewItem("关闭自动更新",$TreeView2)
                $tab2_view[5]=GUICtrlCreateTreeViewItem("任务栏始终显示所有图标",$TreeView2)
                $tab2_view[6]=GUICtrlCreateTreeViewItem("关闭自动播放",$TreeView2)
                $tab2_view[7]=GUICtrlCreateTreeViewItem("桌面显示常用图标",$TreeView2)
                $tab2_view[8]=GUICtrlCreateTreeViewItem("右键增加管理权限",$TreeView2)
                $tab2_view[9]=GUICtrlCreateTreeViewItem("计算机中增加视频设备",$TreeView2)
                $tab2_view[10]=GUICtrlCreateTreeViewItem("删除操作中心图标",$TreeView2)
                $tab2_view[11]=GUICtrlCreateTreeViewItem("不从网络搜索驱动",$TreeView2)
                $tab2_view[12]=GUICtrlCreateTreeViewItem("禁用远程协助",$TreeView2)
               
        
                $tab2button1=GUICtrlCreateButton("全选", 10, 400, 70, 20)
                $tab2button2=GUICtrlCreateButton("全不选", 80, 400, 70, 20)
                $tab2button3=GUICtrlCreateButton("默认", 150, 400, 70, 20)
                $tab2button4=GUICtrlCreateButton("清理", 290, 400, 70, 20)
                $tab2button5=GUICtrlCreateButton("退出", 360, 400, 70, 20)
         
;运行tab2的默认选择
default_select2()
               

        GUISetState()
               

        While 1
                $msg = GUIGetMsg()
                 ;Fitem()
                If $msg = $Tab1button1  Then all_select1()
        If $msg = $Tab1button2  Then all_none1()
        If $msg = $tab1button3  Then default_select1()
        If $msg = $tab1button4  Then clean1()
                If $msg = $Tab1button5  Then ExitLoop
               
        If $msg = $Tab2button1  Then all_select2()
        If $msg = $Tab2button2  Then all_none2()
        If $msg = $Tab2button3  Then default_select2()
       
        If $msg = $Tab2button4  Then clean2()
        If $msg = $Tab2button5  Then ExitLoop
        WEnd
EndFunc   ;==>win7tools










;实现tab1按钮功能

;实现全选功能
Func all_select1()
    GUICtrlSetState($tab1button1,$GUI_DISABLE)
               For $i1 =1 to $t1
             GUICtrlSetState($tab1_view[$i1],$GUI_CHECKED)
             Next
    GUICtrlSetState($tab1button1,$GUI_ENABLE)               
EndFunc

;实现全部不选择功能
Func all_none1()
               For $i1 =1 to $t1
             GUICtrlSetState($Tab1_view[$i1],$GUI_UNCHECKED)
             Next
EndFunc






;实现默认选择功能
Func default_select1()
    GUICtrlSetState($tab1button3,$GUI_DISABLE)
               all_none1()
                 
                 GUICtrlSetState($tab1_view[1],$GUI_CHECKED)
                 GUICtrlSetState($tab1_view[2],$GUI_CHECKED)
                 GUICtrlSetState($tab1_view[4],$GUI_CHECKED)
         GUICtrlSetState($tab1_view[6],$GUI_CHECKED)
               
    GUICtrlSetState($tab1button3,$GUI_ENABLE)   
EndFunc


;tab1清理功能
Func clean1()
     Check1()
select
Case $s1=$t1
       MsgBox(0, "提示", "请选择要清理的项目!@_@")
Case $s1<$t1
    GUICtrlSetState($tab1button4,$GUI_DISABLE)
        For $i1=1 To $t1
                If GUICtrlRead($Tab1_view[$i1]) = $GUI_CHECKED Then
                   Call('Tab1_view'&$i1)
                EndIf
        Next
        GUICtrlSetData($progressbar1,100)
    MsgBox ( 0, "提示", "所选择的项目清理完毕!^_^")
EndSelect
     GUICtrlSetState($tab1button4,$GUI_ENABLE)   
EndFunc

;检查用户是否没有选择任何选项,而直接点击清理的tab1
Func  check1()
            $s1=0
        For $i1 =1 to $t1
             If GUICtrlRead($Tab1_view[$i1]) = $GUI_UNCHECKED Then $s1=$s1+1
                Next
EndFunc       







;实现全选功能tab2
Func all_select2()
         GUICtrlSetState($tab2button1,$GUI_DISABLE)
               For $i2 =1 to 12
             GUICtrlSetState($tab2_view[$i2],$GUI_CHECKED)
         Next       
          GUICtrlSetState($tab2button1,$GUI_ENABLE)         
EndFunc



;实现全部不选功能tab2
Func all_none2()
               For $i2 =1 to $t2
             GUICtrlSetState($tab2_view[$i2],$GUI_UNCHECKED)
         Next
EndFunc


;实现默认选择功能tab2
Func default_select2()
                GUICtrlSetState($tab2button3,$GUI_DISABLE)
                      all_none2()   
                GUICtrlSetState($tab2_view[1],$GUI_CHECKED)
                GUICtrlSetState($tab2_view[2],$GUI_CHECKED)
                GUICtrlSetState($tab2_view[3],$GUI_CHECKED)
                GUICtrlSetState($tab2_view[5],$GUI_CHECKED)
                GUICtrlSetState($tab2_view[6],$GUI_CHECKED)       
                GUICtrlSetState($tab2_view[11],$GUI_CHECKED)
                GUICtrlSetState($tab2_view[12],$GUI_CHECKED)                               
                GUICtrlSetState($tab2button3,$GUI_ENABLE)         
         
EndFunc

;清理开始tab2
Func clean2()
     Check2()
select
Case $s2=$t2
       MsgBox(0, "提示", "请选择要清理的项目!@_@")
Case $s2<$t2
     GUICtrlSetState($tab2button4,$GUI_DISABLE)
        For $i2=1 To $t2
                If GUICtrlRead($Tab2_view[$i2]) = $GUI_CHECKED Then
                   Call('Tab2_view'&$i2)
                EndIf
        Next
            GUICtrlSetData($progressbar2,100)
    MsgBox ( 0, "提示", "所选择的项目清理完毕!^_^")
EndSelect
        GUICtrlSetState($tab2button4,$GUI_ENABLE)   
EndFunc

;检查用户是否没有选择任何选项,而直接点击tab2的清理
Func  check2()
        $s2=0
        For $i1 =1 to $t2
        If GUICtrlRead($tab2_view[$i1])=$GUI_UNCHECKED Then $s2=$s2+1   
        Next
EndFunc       



#cs

;定义项目勾选

Func   Fitem()
        
    If $Msg = $tab1_view[10] And BitAND(GUICtrlRead($tab1_view[10], $GUI_CHECKED)) Then
                For $m=10 To 16
            GUICtrlSetState($tab1_view[$m], $GUI_CHECKED)
        Next

     ElseIf $Msg = $tab1_view[10] And BitAND(GUICtrlRead($tab1_view[10], $GUI_UNCHECKED)) Then ;反选                                    
        For $m=10 To 16
                        GUICtrlSetState($tab1_view[$m],  $GUI_UNCHECKED)
        Next
     EndIf

                       
        If $Msg = $tab1_view[17] And BitAND(GUICtrlRead($tab1_view[17], $GUI_CHECKED)) Then               
        For $m=17 To 25
            GUICtrlSetState($tab1_view[$m], $GUI_CHECKED)
        Next

        ElseIf $Msg = $tab1_view[17] And BitAND(GUICtrlRead($tab1_view[17], $GUI_UNCHECKED)) Then ;反选
        For $i=17 To 25
             GUICtrlSetState($tab1_view[$m],  $GUI_UNCHECKED)
                Next
     EndIf
EndFunc

#ce






错误1:明明一个都没选,点清理时还提示清理完
错误2:由一个检测代码用来检测是不是没选 ,结果没起到作用
错误3:下面被我注解部分想实选勾选父项目,子项目全部勾选功能,但老是提示错误
想实现的功能,子项目勾选,父项目也能勾选,全取消也能取消,
虽然知道发过有一个源码有这个代码,不过太难了,只看到一部分,我只想做我那几个勾选,相信通过这个例子说不定就能掌握勾选功能了
发表于 2011-10-4 22:41:29 | 显示全部楼层

哈哈.......刚看了下.......

囧.
发表于 2011-10-4 23:00:30 | 显示全部楼层
还是for循环的问题。看的头大!多用检测函数检测一下!
发表于 2011-10-4 23:37:11 | 显示全部楼层
本帖最后由 zcool321 于 2011-10-4 23:39 编辑

check1()函数有问题~
第一、GUICtrlRead($tab2_view[$i1])=$GUI_UNCHECKED  不能判断有子集的多选框是否被勾选
第二、GUICtrlRead($tab2_view[$i1])=$GUI_UNCHECKED  判断正常多选框未勾选,但是是点击状态的也会失败~
就是说上面两种情况虽然没有选中~但是GUICtrlRead($tab2_view[$i1])=$GUI_UNCHECKED也是false~

你可以根据GUICtrlRead($tab2_view[$i1])的值判断
未被钩选为:4
未被钩选但为点击状态为:260
根节点(含子集)未被选中为:1028
勾选为:1
勾选且为点击状态为:257
根节点(含子集)勾选为:1025
根节点(含子集)勾选且为点击状态为:1281
这些数据都是我通过调试自己找到的~你可以试试自己看下~

由于封装优化Tab页没有子节点的多选框~所有正常!如果加入子节点的多选框也会出现同样问题~
还有就是建议你把变量的名字改改 和实际内容相符~要不太不容易识别变量的意思了····
 楼主| 发表于 2011-10-5 01:10:30 | 显示全部楼层
在tab2页发现第一次点清理没勾选任何一个,第一次提示没有选择项具,当第二次在点清理时就提示清理完毕了
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-5 15:07 , Processed in 0.078865 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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