找回密码
 加入
搜索
查看: 7031|回复: 11

[GUI管理] 怎么在搜索文件的同时用进度条显示进度

  [复制链接]
发表于 2014-2-10 17:19:03 | 显示全部楼层 |阅读模式
搜索大量文件时怎么把搜索的进度显示出来呢?
以下这样写我自知是不能同步的了,请问怎么怎么搜索时显示进度?谢谢。。。

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <file.au3>
#Region ### START Koda GUI section ### Form=C:\Users\Administrator\Desktop\测试进度条.kxf
$Form1 = GUICreate("测试进度条", 615, 438, 192, 124)
$Label1 = GUICtrlCreateLabel(" ", 96, 80, 36, 17)
$Progress1 = GUICtrlCreateProgress(96, 104, 406, 17)
$Button1 = GUICtrlCreateButton("开始", 432, 184, 75, 25)
$Inpute = GUICtrlCreateInput("", 96, 24, 361, 21)
$Button2 = GUICtrlCreateButton("...", 464, 24, 43, 21)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button2
                        GUICtrlSetData($Inpute,FileSelectFolder("",""))
                Case $Button1
                        GUICtrlSetData($Progress1,0)
                        Local $list = _FileListToArrayRec(GUICtrlRead($Inpute),"*",0,1,0,2) ;把搜索结果存入到数组中
                        For $i = 1 To $list[0] ;从第一个到最大值
                                GUICtrlSetData($Progress1,$i) ;这样写进度条直接走完,因为搜索完再写进度,应该怎么做才能同步?
                        Next
        EndSwitch
WEnd
发表于 2014-2-10 19:09:13 | 显示全部楼层
搜索完成才能知道总量,搜索过程中没有总量用进度条又有何用?当然循环走道的进度条除外~~
 楼主| 发表于 2014-2-10 19:32:02 | 显示全部楼层
回复 2# afan


    大侠请赐教!
发表于 2014-2-10 19:50:05 | 显示全部楼层
就是走马灯似的进度条… 没啥意义的,而且非标准进度条,做起来比较繁琐。如果需要用这种进度条,可以搜索本坛,记得有个UDF
发表于 2014-2-11 20:01:45 | 显示全部楼层
本帖最后由 hnfeng 于 2014-2-12 08:15 编辑

回复 1# 不死帝国


简单的话,就用 SplashTextOn 弹出一个文字框
动态的就用下面代码
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
Example()
Func Example()
    GUICreate("正在xxx,请稍等……", 290, 90, -1, -1)
    Local $iProgress = GUICtrlCreateProgress(10, 10, 270, 20, $PBS_MARQUEE)
    Local $iStart = GUICtrlCreateButton("开始 &S", 10, 60, 70, 25)
    Local $iStop = GUICtrlCreateButton("停止 &t", 85, 60, 70, 25)
    GUISetState(@SW_SHOW)
    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $iStart
                GUICtrlSendMsg($iProgress, $PBM_SETMARQUEE, 1, 50)
            Case $iStop
                GUICtrlSendMsg($iProgress, $PBM_SETMARQUEE, 0, 50)
        EndSwitch
    WEnd
EndFunc
 楼主| 发表于 2014-2-12 10:21:18 | 显示全部楼层
我自己用 FileFindFirstFile 和 FileFindNextFile 进行搜索;在循环内对进度条进行操作;但也是一下子走完;根本与搜索时不是同步;文件还在搜索中;进度条已经走完了。

AU3的进度条有最大值设置的吗?如果不能设置最大值那不就是只有100%就走满了?
发表于 2014-2-12 10:36:14 | 显示全部楼层
回复 6# 不死帝国


2楼已经说的明白了的:搜索完成才能知道总量,所以你无法给进度条一个实时值,所以这里你搞个进度条,因为无法知道总量,就无法计算进度条的百分比。

这个地方一般常用的就是我前面说的两种方法(也有弹出一个视频或做一个不断显示不同图片的弹窗),文本提示窗简单,走马灯进度条(或者叫 等待进度条,忙碌进度条)因为无始无终无头无尾,无需知道总量,只是提示用户需要等待……,许多程序都用这种方法。

普通进度条是按 百分比 来设置进度的,最小是0,最大是100
发表于 2014-2-12 15:51:12 | 显示全部楼层
其实也不是不可能,就是烦了点
发表于 2014-2-12 15:53:59 | 显示全部楼层
先获取文件夹大小,在获取一个文件的时候,减去文件大小,类推......减完了然后就是0,进度条就是100%
发表于 2014-2-14 22:17:32 | 显示全部楼层
本帖最后由 58fly 于 2014-2-14 22:19 编辑

回复 1# 不死帝国


   以下方法仅是一种提供准确进度条的方案,如果你的遍历数量太大,会影响效率(因为是2次遍历)
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <file.au3>
#Region ### START Koda GUI section ### Form=C:\Users\Administrator\Desktop\测试进度条.kxf
$Form1 = GUICreate("测试进度条", 615, 438, 192, 124)
$Label1 = GUICtrlCreateLabel(" ", 96, 80, 36, 17)
$Progress1 = GUICtrlCreateProgress(96, 104, 406, 17)
$Button1 = GUICtrlCreateButton("开始", 432, 184, 75, 25)
$Inpute = GUICtrlCreateInput("", 96, 24, 361, 21)
$Button2 = GUICtrlCreateButton("...", 464, 24, 43, 21)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button2
                        GUICtrlSetData($Inpute,FileSelectFolder("",""))
                Case $Button1
                        GUICtrlSetData($Progress1,0)
                        Local $list = _FileListToArrayRec(GUICtrlRead($Inpute),"*",0,1,0,2) ;把搜索结果存入到数组中
                        
                         Local $file_x = 0
                                                
                        GUICtrlSetData($Label1,"正在计算..")
                        For $i = 1 To $list[0] ;先计算文件数量
                           $file_x = $i +1
                        Next
                                                
                        For $i = 1 To $list[0] ;从第一个到最大值
                                GUICtrlSetData($Progress1,$i / $file_x * 100) ;准确进度条(按文件数量)
                        Next
        EndSwitch
WEnd
 楼主| 发表于 2014-3-1 08:53:39 | 显示全部楼层
回复 11# 58fly


    首先感谢你的解答;我实测以你这种方法计算出来的进度也是不太精确的;文件搜索完成到计算进度,进度条始终是不能走满的。加上这样本来做一次的工作需要做两次。进度条也真是个麻烦的家伙啊。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-1 03:40 , Processed in 0.080538 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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