找回密码
 加入
搜索
查看: 2078|回复: 2

[AU3基础] 求助,关于循环暂停的问题.

[复制链接]
发表于 2010-5-31 17:22:34 | 显示全部楼层 |阅读模式
本帖最后由 setqsetq 于 2010-5-31 17:30 编辑

为什么按开始键不开始搜索.
按完开始再按停止,有时多点几次就可以了?为什么啊?..
怎样修改呢??

#include <WindowsConstants.au3>
#include <GuiConstants.au3>
GUICreate("MyGUI", 450 ,150, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))

$Progress_1 = GUICtrlCreateProgress(10, 10, 370, 20)
$Label1 = GUICtrlCreateLabel("扫描目录", 24, 80, 52, 17)
$Label2 = GUICtrlCreateLabel("", 24, 112, 276, 17)
$Button_2 = GUICtrlCreateButton("开始", 10, 40, 60, 30)
$Button_3 = GUICtrlCreateButton("停止", 80, 40, 60, 30)
$Button_4 = GUICtrlCreateButton("退出", 150, 40, 70, 30)

Opt("GUIOnEventMode", 1)
Dim $start = -1, $ostart
Global $pause = True

GUISetState()
GUISetOnEvent($GUI_EVENT_CLOSE, "gui")
GUICtrlSetOnEvent($Button_2, "gui")
GUICtrlSetOnEvent($Button_3, "gui")
GUICtrlSetOnEvent($Button_4, "gui")

While 1
        If $pause = False Then
                $start = 0
                $Drive = DriveGetDrive("FIXED")
                For $i = 1 To $Drive[0]
                        If $pause = False Then
                                _filelist($Drive[$i])
                        EndIf
                Next
        EndIf
WEnd


Func gui()
        Switch @GUI_CtrlId
                Case $GUI_EVENT_CLOSE, $Button_4
                        $pause = True
                        Exit
                Case $Button_2
                        $pause = False                        
                Case $Button_3
                        $pause = True                        
        EndSwitch
EndFunc   ;==>gui


Func _filelist($searchdir)
        $search = FileFindFirstFile($searchdir & "\*.*") ;;;;查指定目录下的文件
        If $search = -1 Then Return -1 ;;;;如果找不到,返回值 -1
        While 1
                If $pause = False Then ExitLoop
                $file = FileFindNextFile($search) ;;;查找下一个文件
                If @error Then ;;;如果找不到文件
                        FileClose($search) ;;;则关闭此句柄
                        Return ;;;返回
                ElseIf $file = "." Or $file = ".." Then ;;如果找到的文件名为.或..则ContinueLoop
                        ContinueLoop ;;;在某些版本的AU3里面可以不需要上行和这行。
                ElseIf StringInStr(FileGetAttrib($searchdir & "\" & $file), "D") Then ;;如果找到的是一个文件夹,则
                        _filelist($searchdir & "\" & $file) ;;递归调用filelist函数,并传参数  "$searchdir & "\" & $file"
                        GUICtrlSetData($Label2, $searchdir & "\" & $file) ;显示搜索文件夹
                        GUICtrlSetData($Progress_1, $start)
                        $start = $start + 0.1
                EndIf ;;;$file为查找到的文件夹名称,上一行意思就是进入此文件夹继续查找文件.如此循环
                ConsoleWrite($searchdir & "\" & $file & @CRLF)
;~                 If StringInStr($file, 'QQ.exe') Then MsgBox(0, 0, $searchdir & "\" & $file & @CRLF)
        WEnd
EndFunc   ;==>_filelist
发表于 2010-6-1 01:54:35 | 显示全部楼层
本帖最后由 foboy 于 2010-6-1 02:20 编辑

时间关系, 只稍微改了一下。
当然还有很多问题。
一点意见:
主循环里,当点了开始以后,一次查找完毕后应主动设置pause为true ,否则会不停循环查找下去。
你的进度条有点欺骗的味道,找到一个文件就增加千分之一。往往刚开始查找,进度条就满了。不过我想我短时间内也最不好精确的进度。只是来随便转转。
你也喜欢用事件模式,我们是同类。可以加我交流一下经验。我的QQ114026307 博客 :maijiaoben.com
#include <WindowsConstants.au3>
#include <GuiConstants.au3>
Opt("TrayIconDebug", 1)
GUICreate("MyGUI", 450, 150, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))

$Progress_1 = GUICtrlCreateProgress(10, 10, 370, 20)
$Label1 = GUICtrlCreateLabel("扫描目录", 24, 80, 52, 17)
$Label2 = GUICtrlCreateLabel("", 24, 112, 276, 17)
$Button_2 = GUICtrlCreateButton("开始", 10, 40, 60, 30)
$Button_3 = GUICtrlCreateButton("停止", 80, 40, 60, 30)
$Button_4 = GUICtrlCreateButton("退出", 150, 40, 70, 30)

Opt("GUIOnEventMode", 1)
Dim $start = -1, $ostart
Global $pause = True

GUISetState()
GUISetOnEvent($GUI_EVENT_CLOSE, "gui")
GUICtrlSetOnEvent($Button_2, "gui")
GUICtrlSetOnEvent($Button_3, "gui")
GUICtrlSetOnEvent($Button_4, "gui")
GUICtrlSetState($Button_3, $gui_disable)
While 1
        If $pause = False Then
                $Drive = DriveGetDrive("FIXED")
                For $i = 1 To $Drive[0]
                        If $pause == True Then ExitLoop
                        _filelist($Drive[$i], $i - 1, $Drive[0])
                Next
                $pause = True
        EndIf
WEnd

Func gui()
        Switch @GUI_CtrlId
                Case $GUI_EVENT_CLOSE, $Button_4
                        $pause = True
                        Exit
                Case $Button_2
                        $pause = False
                        GUICtrlSetState($Button_2, $gui_disable)
                        GUICtrlSetState($Button_3, $gui_enable)
                Case $Button_3
                        $pause = True
                        GUICtrlSetState($Button_3, $gui_disable)
                        GUICtrlSetState($Button_2, $gui_enable)
        EndSwitch
EndFunc   ;==>gui


Func _filelist($searchdir = "", $now = 0, $all = 0)
        $search = FileFindFirstFile($searchdir & "\*.*") ;;;;查指定目录下的文件
        If $search = -1 Then Return -1 ;;;;如果找不到,返回值 -1
        While 1
                If $pause == True Then ExitLoop
                $file = FileFindNextFile($search) ;;;查找下一个文件
                If @error Then ;;;如果找不到文件
                        FileClose($search) ;;;则关闭此句柄
                        Return ;;;返回
                ElseIf $file = "." Or $file = ".." Then ;;如果找到的文件名为.或..则ContinueLoop
                        ContinueLoop ;;;在某些版本的AU3里面可以不需要上行和这行。
                ElseIf StringInStr(FileGetAttrib($searchdir & "" & $file), "D") Then ;;如果找到的是一个文件夹,则
                        _filelist($searchdir & "" & $file) ;;递归调用filelist函数,并传参数  "$searchdir & "" & $file"
                        GUICtrlSetData($Label2, $searchdir & "" & $file) ;显示搜索文件夹
                EndIf ;;;$file为查找到的文件夹名称,上一行意思就是进入此文件夹继续查找文件.如此循环
                ConsoleWrite($searchdir & "" & $file & @CRLF)
;~                 If StringInStr($file, 'QQ.exe') Then MsgBox(0, 0, $searchdir & "" & $file & @CRLF)
        WEnd
EndFunc   ;==>_filelist
发表于 2010-6-1 05:17:04 | 显示全部楼层
呵呵,这进度条是不可能准确的,只能用回滚式.
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-22 07:11 , Processed in 0.077686 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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