找回密码
 加入
搜索
查看: 9068|回复: 19

[AU3基础] 求助 类似 ATI 驱动安装过程中的双进度条如何实现。

 火.. [复制链接]
发表于 2012-2-2 22:01:55 | 显示全部楼层 |阅读模式
本帖最后由 cpark 于 2012-2-2 22:55 编辑

下面这段代码 带2个进度条,上面的宽的那个 显示 总体进度
下面的那个显示当前进度
我想实现 总体进度 由程序控制
下面的那个当前进度就一直自己跑
模仿的是ATI的驱动安装界面的进度条

下面的代码在效果上实现了,但是无法使用,因为进入一个循环了
有咩有同学能实现这个效果,而且代码能正常使用的
#include <GUIConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#region ### START Koda GUI section ### Form=
$Form2 = GUICreate("窗体1", 413, 305, -1, -1)
$Button1 = GUICtrlCreateButton("Button1", 315, 255, 75, 25)
GUISetState(@SW_SHOW)

Global $FRM_PROGRESS = GUICreate("", 566, 168, -1, -1, BitOR($WS_POPUP, $DS_SETFOREGROUND, $WS_BORDER), BitOR($WS_EX_TOPMOST, $WS_EX_WINDOWEDGE ), $Form2)
GUICtrlCreateGroup("", -99, -99, 1, 1)
Global $GRP_STEP = GUICtrlCreateGroup("", 10, 5, 151, 151)
Global $LABEL_STEP_DESCRIBE = GUICtrlCreateLabel("STEP:", 20, 15, 75, 32)
GUICtrlSetFont(-1, 18, 800, 2, "Arial")
Global $LABEL_STEP_COUNT = GUICtrlCreateLabel("", 20, 50, 130, 94, $SS_RIGHT)
GUICtrlSetFont(-1, 68, 400, 2, "Arial")

GUICtrlCreateGroup("", -99, -99, 1, 1)
Global $GRP_OVERALL = GUICtrlCreateGroup("", 170, 5, 385, 80)
Global $LABEL_OVERALL = GUICtrlCreateLabel("整体进度:", 180, 20, 64, 17)
Global $PROGRESS_OVERALL = GUICtrlCreateProgress(180, 40, 363, 36)

GUICtrlCreateGroup("", -99, -99, 1, 1)
Global $GRP_CURRENT = GUICtrlCreateGroup("", 170, 90, 385, 65)
Global $LABEL_CURRENT = GUICtrlCreateLabel("当前操作:", 180, 105, 64, 17)
Global $PROGRESS_CURENT = GUICtrlCreateProgress(180, 125, 363, 21)

#endregion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit

                Case $Button1
                        GUISetState(@SW_HIDE, $Form2)
                        GUISetState(@SW_SHOW, $FRM_PROGRESS)
                        While 1
                                                For $i = 10 To 100 Step 10
                        Sleep(100)
                        GUICtrlSetData($PROGRESS_CURENT, $i)
                Next
                                WEnd
        EndSwitch
WEnd
根据A版的提示,重新做了代码,和我想的效果一抹一样,而且最好玩的是,在主进度条在一个循环内部的时候,AdlibRegister注册的函数还是会正常执行,而不是等待主进度的循环结束在进行!
学习了
多谢A版
#include <GUIConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#region ### START Koda GUI section ### Form=
$Form2 = GUICreate("窗体1", 413, 305, -1, -1)
$Button1 = GUICtrlCreateButton("Button1", 315, 255, 75, 25)
GUISetState(@SW_SHOW)

Global $ix_loop = 0
Global $FRM_PROGRESS = GUICreate("", 566, 168, -1, -1, BitOR($WS_POPUP, $DS_SETFOREGROUND, $WS_BORDER), BitOR($WS_EX_TOPMOST, $WS_EX_WINDOWEDGE), $Form2)
GUICtrlCreateGroup("", -99, -99, 1, 1)
Global $GRP_STEP = GUICtrlCreateGroup("", 10, 5, 151, 151)
Global $LABEL_STEP_DESCRIBE = GUICtrlCreateLabel("STEP:", 20, 15, 75, 32)
GUICtrlSetFont(-1, 18, 800, 2, "Arial")
Global $LABEL_STEP_COUNT = GUICtrlCreateLabel("", 20, 50, 130, 94, $SS_RIGHT)
GUICtrlSetFont(-1, 68, 400, 2, "Arial")

GUICtrlCreateGroup("", -99, -99, 1, 1)
Global $GRP_OVERALL = GUICtrlCreateGroup("", 170, 5, 385, 80)
Global $LABEL_OVERALL = GUICtrlCreateLabel("整体进度:", 180, 20, 64, 17)
Global $PROGRESS_OVERALL = GUICtrlCreateProgress(180, 40, 363, 36)

GUICtrlCreateGroup("", -99, -99, 1, 1)
Global $GRP_CURRENT = GUICtrlCreateGroup("", 170, 90, 385, 65)
Global $LABEL_CURRENT = GUICtrlCreateLabel("当前操作:", 180, 105, 64, 17)
Global $PROGRESS_CURENT = GUICtrlCreateProgress(180, 125, 363, 21)

#endregion ### END Koda GUI section ###
AdlibRegister("_refreshProgressBar")
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit

                Case $Button1
                        GUISetState(@SW_HIDE, $Form2)
                        GUISetState(@SW_SHOW, $FRM_PROGRESS)
                        For $i = 10 To 100 Step 10
                                Sleep(1000)
                                GUICtrlSetData($PROGRESS_OVERALL, $i)
                        Next
        EndSwitch
WEnd
Func _refreshProgressBar()

        $ix_loop = $ix_loop+10

        If $ix_loop > 100 Then $ix_loop = 0

        GUICtrlSetData($PROGRESS_CURENT, $ix_loop)

EndFunc   ;==>_refreshProgressBar
发表于 2012-2-2 22:22:51 | 显示全部楼层
AdlibRegister()
 楼主| 发表于 2012-2-2 22:34:17 | 显示全部楼层
如果我用AdlibRegister()调用一个函数,这个函数内容如下:

Func _refreshProgressBar()
        For $i = 10 To 100 Step 10
                Sleep(1000)
                GUICtrlSetData($PROGRESS_CURENT, $i)
        Next
EndFunc   ;==>_refreshProgressBar

然后用 AdlibRegister("_refreshProgressBar", "1000")

那么在_refreshProgressBar函数执行这个过程中,是不是其脚本就干不了别的呢?
发表于 2012-2-2 22:39:59 | 显示全部楼层
Global $ix_loop = 0
AdlibRegister("_refreshProgressBar", "1000")

Func _refreshProgressBar()
        $ix_loop += 10
        If $ix_loop > 100 Then $ix_loop = 0
        GUICtrlSetData($PROGRESS_CURENT, $ix_loop)
EndFunc   ;==>_refreshProgressBar
发表于 2012-2-2 22:46:34 | 显示全部楼层
本帖最后由 auto 于 2012-2-2 22:52 编辑

#include <GUIConstants.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <ProgressConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #region ### START Koda GUI section ### Form= $Form2 = GUICreate("窗体1", 413, 305, -1, -1) $Button1 = GUICtrlCreateButton("Button1", 315, 255, 75, 25) GUISetState(@SW_SHOW)  Global $FRM_PROGRESS = GUICreate("", 566, 168, -1, -1, BitOR($WS_POPUP, $DS_SETFOREGROUND, $WS_BORDER), BitOR($WS_EX_TOPMOST, $WS_EX_WINDOWEDGE), $Form2) GUICtrlCreateGroup("", -99, -99, 1, 1) Global $GRP_STEP = GUICtrlCreateGroup("", 10, 5, 151, 151) Global $LABEL_STEP_DESCRIBE = GUICtrlCreateLabel("STEP:", 20, 15, 75, 32) GUICtrlSetFont(-1, 18, 800, 2, "Arial") Global $LABEL_STEP_COUNT = GUICtrlCreateLabel("", 20, 50, 130, 94, $SS_RIGHT) GUICtrlSetFont(-1, 68, 400, 2, "Arial")  GUICtrlCreateGroup("", -99, -99, 1, 1) Global $GRP_OVERALL = GUICtrlCreateGroup("", 170, 5, 385, 80) Global $LABEL_OVERALL = GUICtrlCreateLabel("整体进度:", 180, 20, 64, 17) Global $PROGRESS_OVERALL = GUICtrlCreateProgress(180, 40, 363, 36)  GUICtrlCreateGroup("", -99, -99, 1, 1) Global $GRP_CURRENT = GUICtrlCreateGroup("", 170, 90, 385, 65) Global $LABEL_CURRENT = GUICtrlCreateLabel("当前操作:", 180, 105, 64, 17) Global $PROGRESS_CURENT = GUICtrlCreateProgress(180, 125,363, 21)  #endregion ### END Koda GUI section ###  While 1         $nMsg = GUIGetMsg()         Switch $nMsg                 Case $GUI_EVENT_CLOSE                         Exit                  Case $Button1                         GUISetState(@SW_HIDE, $Form2)                         GUISetState(@SW_SHOW, $FRM_PROGRESS)                         For $j = 1 To 101 Step 2                                 For $x = 1 To 200 Step 2                                         ;ConsoleWrite($i)                                         GUICtrlSetData($PROGRESS_CURENT, $x)                                         Sleep(5)                                 Next                                 GUICtrlSetData($PROGRESS_OVERALL, $j)                         Next         EndSwitch WEnd 


发现$i =1 to 100 只能刷新进步到一半左右就没空了,只有200才是满进度。。有点奇怪

还有奇怪我的AU3代码贴上来都成一行了??
发表于 2012-2-2 22:51:25 | 显示全部楼层
发现$i =1 to 100 只能刷新进步到一半左右就没空了,只有200才是满进度。。有点奇怪
auto 发表于 2012-2-2 22:46



    “Step 2” 100 / 2 = 50 当然只到一半
 楼主| 发表于 2012-2-2 22:52:59 | 显示全部楼层
感谢AFan版主,搞定了,和我想的效果一模一样!!!!
整理了一下代码,重新贴上 :)
发表于 2012-2-2 22:54:05 | 显示全部楼层
setp 2 不是表示 $i 每一次循环加2吗?
 楼主| 发表于 2012-2-2 22:56:32 | 显示全部楼层
根据A版的提示,重新做了代码,和我想的效果一抹一样,而且最好玩的是,在主进度条在一个循环内部的时候,AdlibRegister注册的函数还是会正常执行,而不是等待主进度的循环结束在进行!
学习了
多谢A版
发表于 2012-2-2 22:57:52 | 显示全部楼层
回复 6# afan
    #include <GUIConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#region ### START Koda GUI section ### Form=
$Form2 = GUICreate("窗体1", 413, 305, -1, -1)
$Button1 = GUICtrlCreateButton("Button1", 315, 255, 75, 25)
GUISetState(@SW_SHOW)

Global $FRM_PROGRESS = GUICreate("", 566, 168, -1, -1, BitOR($WS_POPUP, $DS_SETFOREGROUND, $WS_BORDER), BitOR($WS_EX_TOPMOST, $WS_EX_WINDOWEDGE), $Form2)
GUICtrlCreateGroup("", -99, -99, 1, 1)
Global $GRP_STEP = GUICtrlCreateGroup("", 10, 5, 151, 151)
Global $LABEL_STEP_DESCRIBE = GUICtrlCreateLabel("STEP:", 20, 15, 75, 32)
GUICtrlSetFont(-1, 18, 800, 2, "Arial")
Global $LABEL_STEP_COUNT = GUICtrlCreateLabel("", 20, 50, 130, 94, $SS_RIGHT)
GUICtrlSetFont(-1, 68, 400, 2, "Arial")

GUICtrlCreateGroup("", -99, -99, 1, 1)
Global $GRP_OVERALL = GUICtrlCreateGroup("", 170, 5, 385, 80)
Global $LABEL_OVERALL = GUICtrlCreateLabel("整体进度:", 180, 20, 64, 17)
Global $PROGRESS_OVERALL = GUICtrlCreateProgress(180, 40, 363, 36)

GUICtrlCreateGroup("", -99, -99, 1, 1)
Global $GRP_CURRENT = GUICtrlCreateGroup("", 170, 90, 385, 65)
Global $LABEL_CURRENT = GUICtrlCreateLabel("当前操作:", 180, 105, 64, 17)
Global $PROGRESS_CURENT = GUICtrlCreateProgress(180, 125,363, 21)

#endregion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit

                Case $Button1
                        GUISetState(@SW_HIDE, $Form2)
                        GUISetState(@SW_SHOW, $FRM_PROGRESS)
                        For $j = 0 To 100 Step 2
                                For $x = 0 To 100 Step 2
                                        GUICtrlSetData($PROGRESS_CURENT, $x)
                                        Sleep(5)        
                                Next
                                ;Sleep(1000)
                                GUICtrlSetData($PROGRESS_OVERALL, $j)
                        Next
        EndSwitch
WEnd
sleep(1000)注释掉就看可以问题了
 楼主| 发表于 2012-2-2 23:04:30 | 显示全部楼层
回复 10# auto

两位大大都在,正好讨论下

AFan版主的代码我觉得是正确的,因为在更新 进度条的过程中 程序还可以执行别的命令
而auto的代码和我最初写的是一样的,因为进入了循环,所以在更新进度条的过程中无法执行其他的操作

AFan版主有研究过AdlibRegister()的工作模式么,可以讲解一下么?
发表于 2012-2-2 23:08:58 | 显示全部楼层
发现$i =1 to 100 只能刷新进步到一半左右就没空了,只有200才是满进度。。有点奇怪

还有奇怪我的AU ...
auto 发表于 2012-2-2 22:46


#include <GUIConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$Form2 = GUICreate("窗体1", 413, 305, -1, -1)
$Button1 = GUICtrlCreateButton("Button1", 315, 255, 75, 25)
GUISetState(@SW_SHOW)
Global $ix_loop = 0, $ix_loopMain = 0
Global $FRM_PROGRESS = GUICreate("", 566, 168, -1, -1, BitOR($WS_POPUP, $DS_SETFOREGROUND, $WS_BORDER), BitOR($WS_EX_TOPMOST, $WS_EX_WINDOWEDGE), $Form2)
GUICtrlCreateGroup("", -99, -99, 1, 1)
Global $GRP_STEP = GUICtrlCreateGroup("", 10, 5, 151, 151)
Global $LABEL_STEP_DESCRIBE = GUICtrlCreateLabel("STEP:", 20, 15, 75, 32)
GUICtrlSetFont(-1, 18, 800, 2, "Arial")
Global $LABEL_STEP_COUNT = GUICtrlCreateLabel("", 20, 50, 130, 94, $SS_RIGHT)
GUICtrlSetFont(-1, 68, 400, 2, "Arial")

GUICtrlCreateGroup("", -99, -99, 1, 1)
Global $GRP_OVERALL = GUICtrlCreateGroup("", 170, 5, 385, 80)
Global $LABEL_OVERALL = GUICtrlCreateLabel("整体进度:", 180, 20, 64, 17)
Global $PROGRESS_OVERALL = GUICtrlCreateProgress(180, 40, 363, 36)

GUICtrlCreateGroup("", -99, -99, 1, 1)
Global $GRP_CURRENT = GUICtrlCreateGroup("", 170, 90, 385, 65)
Global $LABEL_CURRENT = GUICtrlCreateLabel("当前操作:", 180, 105, 64, 17)
Global $PROGRESS_CURENT = GUICtrlCreateProgress(180, 125, 363, 21)

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case -3
                        Exit

                Case $Button1
                        Dim $ix_loop = 0, $ix_loopMain = 0
                        GUISetState(@SW_HIDE, $Form2)
                        GUISetState(@SW_SHOW, $FRM_PROGRESS)
                        AdlibRegister("_refreshProgressBar", "100")
        EndSwitch
WEnd

Func _refreshProgressBar()
        $ix_loop += 10
        If $ix_loop > 100 Then
                $ix_loopMain += 30
                If $ix_loopMain > 100 Then
                        $ix_loopMain = 100
                        AdlibUnRegister()
                        GUICtrlSetData($PROGRESS_OVERALL, $ix_loopMain)
                        Sleep(500)
                        GUISetState(@SW_HIDE, $FRM_PROGRESS)
                        GUISetState(@SW_SHOW, $Form2)
                        GUICtrlSetData($PROGRESS_OVERALL, 0)
                        Return
                EndIf
                GUICtrlSetData($PROGRESS_OVERALL, $ix_loopMain)
                $ix_loop = 0
        EndIf
        GUICtrlSetData($PROGRESS_CURENT, $ix_loop)
EndFunc   ;==>_refreshProgressBar
发表于 2012-2-2 23:09:04 | 显示全部楼层
回复 11# cpark

我是在你的代码修改的实现,实际应用肯定不行啦,只是用来模拟的双进度的显示
    adlibregister是类似定时器工作模式,但不是真正的定时器
 楼主| 发表于 2012-2-2 23:14:33 | 显示全部楼层
我去把函数写出来,再贴上来给两位大大 :)
 楼主| 发表于 2012-2-2 23:40:04 | 显示全部楼层
本帖最后由 cpark 于 2012-2-2 23:48 编辑

想把上面的功能封装成函数,但是怎么都运行不起来,两个大大帮忙看下,什么问题
Func _SET_PROGRESS_STATE($OVERALL_DESC, $OVERALL_RATE, $STEP_COUNT = "", $CURRENT_DESC = "", $CURENT_RATE = "", $PARRENTFRM = "")
        Global $PROGRESS_CURENT_LOOP = 0
        If $PARRENTFRM <> "" Then
                Global $FRM_PROGRESS = GUICreate("", 566, 168, -1, -1, BitOR($WS_POPUP, $DS_SETFOREGROUND, $WS_BORDER), BitOR($WS_EX_TOPMOST, $WS_EX_WINDOWEDGE), $PARRENTFRM)
                ;Global $FRM_PROGRESS = GUICreate("", 566, 168, -1, -1, -2139094528, BitOR($WS_EX_TOPMOST, $WS_EX_WINDOWEDGE), $PARRENTFRM)
                GUICtrlCreateGroup("", -99, -99, 1, 1)
                Global $GRP_STEP = GUICtrlCreateGroup("", 10, 5, 151, 151)
                Global $LABEL_STEP_DESCRIBE = GUICtrlCreateLabel("STEP:", 20, 15, 75, 32)
                GUICtrlSetFont(-1, 18, 800, 2, "Arial")
                Global $LABEL_STEP_COUNT = GUICtrlCreateLabel("", 20, 50, 130, 94, $SS_RIGHT)
                GUICtrlSetFont(-1, 68, 400, 2, "Arial")

                GUICtrlCreateGroup("", -99, -99, 1, 1)
                Global $GRP_OVERALL = GUICtrlCreateGroup("", 170, 5, 385, 80)
                Global $LABEL_OVERALL = GUICtrlCreateLabel("整体进度:", 180, 20, 64, 17)
                Global $PROGRESS_OVERALL = GUICtrlCreateProgress(180, 40, 363, 36)

                GUICtrlCreateGroup("", -99, -99, 1, 1)
                Global $GRP_CURRENT = GUICtrlCreateGroup("", 170, 90, 385, 65)
                Global $LABEL_CURRENT = GUICtrlCreateLabel("当前操作:", 180, 105, 64, 17)
                Global $PROGRESS_CURENT = GUICtrlCreateProgress(180, 125, 363, 21)
                
                GUISetState(@SW_HIDE, $PARRENTFRM)
                GUISetState(@SW_SHOW, $FRM_PROGRESS)
        EndIf

        GUICtrlSetData($LABEL_OVERALL, $OVERALL_DESC)
        GUICtrlSetData($PROGRESS_OVERALL, $OVERALL_RATE)
        GUICtrlSetData($LABEL_STEP_COUNT, $STEP_COUNT)
        GUICtrlSetData($LABEL_CURRENT, $CURRENT_DESC)
        
        If $CURENT_RATE <> "" Then
                GUICtrlSetData($PROGRESS_CURENT, $CURENT_RATE)
        Else
                If $PROGRESS_CURENT_LOOP <> 0 Then AdlibRegister("_REFRESS_PROGRESS_BAR")
        EndIf

EndFunc   ;==>_SET_PROGRESS_STATE

Func _REFRESS_PROGRESS_BAR()

        $PROGRESS_CURENT_LOOP = $PROGRESS_CURENT_LOOP + 10
        If $PROGRESS_CURENT_LOOP > 100 Then $PROGRESS_CURENT_LOOP = 0
        GUICtrlSetData($PROGRESS_CURENT, $PROGRESS_CURENT_LOOP)

EndFunc   ;==>_REFRESS_PROGRESS_BAR
#include <GUIConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <_SET_PROGRESS_STATE.au3>
#region ### START Koda GUI section ### Form=
$Form2 = GUICreate("窗体1", 413, 305, -1, -1)
$Button1 = GUICtrlCreateButton("Button1", 315, 255, 75, 25)
GUISetState(@SW_SHOW)

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit

                Case $Button1
                        _SET_PROGRESS_STATE("测试开始了", 0, 1, "自己跑,不用管,哈哈哈。。", $Form2)
                        For $i = 1 To 100 Step 10
                                Sleep(1000)
                                _SET_PROGRESS_STATE("已经循环了 " & $i & "次", $i, $i)
                        Next
        EndSwitch
WEnd
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-12-25 10:46 , Processed in 0.099758 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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