找回密码
 加入
搜索
查看: 3583|回复: 8

循环再套循环 然后判断按钮的问题

[复制链接]
发表于 2008-12-19 21:10:39 | 显示全部楼层 |阅读模式
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("QQ2009 下载器", 330, 74)
$Progress1 = GUICtrlCreateProgress(8, 8, 313, 25)
$Button1 = GUICtrlCreateButton("开始下载", 88, 40, 113, 25, $BS_DEFPUSHBUTTON)
$Button2 = GUICtrlCreateButton("取消下载", 208, 40, 113, 25, 0)
GUICtrlSetState(-1, $GUI_DISABLE)
$Label1 = GUICtrlCreateLabel("未下载", 8, 48, 72, 17)
GUISetState(@SW_SHOW)

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        GUICtrlSetState($Button1, $GUI_DISABLE)
                        GUICtrlSetState($Button2, $GUI_ENABLE)
                        InetGet("http://dl_dir.qq.com/qqfile/qq/QQ2009preview4/QQ2009Preview4_chs.exe",@ScriptDir & "\qq.exe", 1, 1)
                        While @InetGetActive
                                If GUIGetMsg() = $Button2 Then
                                        InetGet("abort")
                                        GUICtrlSetState($Button1, $GUI_ENABLE)
                                        GUICtrlSetState($Button2, $GUI_DISABLE)
                                        GUICtrlSetData($Label1,"未下载")
                                        MsgBox(0,"QQ2009 下载器","下载已取消!")
                                        ExitLoop
                                EndIf
                                If GUIGetMsg() = $GUI_EVENT_CLOSE Then
                                        Exit
                                EndIf
                                Sleep(1000)
                                If @InetGetActive = 0 Then
                                        MsgBox(0,"QQ2009 下载器","下载完成!")
                                        Exit
                                EndIf
                                $baifenbi1 = 18298176 / 100
                                $baifenbi = @InetGetBytesRead / $baifenbi1
                                GUICtrlSetData($Progress1,$baifenbi)
                                GUICtrlSetData($Label1,@InetGetBytesRead & " 字节")
                        WEnd
        EndSwitch
WEnd

为什么点击“取消下载”半天才有反映。。。

[ 本帖最后由 78391493 于 2008-12-20 09:31 编辑 ]
发表于 2008-12-19 22:31:26 | 显示全部楼层
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

$SetDown = 0
$Form1 = GUICreate("QQ2009 下载器", 330, 74)
$Progress1 = GUICtrlCreateProgress(8, 8, 313, 25)
$Button1 = GUICtrlCreateButton("开始下载", 88, 40, 113, 25, $BS_DEFPUSHBUTTON)
$Button2 = GUICtrlCreateButton("取消下载", 208, 40, 113, 25, 0)
GUICtrlSetState(-1, $GUI_DISABLE)
$Label1 = GUICtrlCreateLabel("未下载", 8, 48, 72, 17)
GUISetState(@SW_SHOW)
AdlibEnable("detect",500)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
                        $SetDown = 1
            GUICtrlSetState($Button1, $GUI_DISABLE)
            GUICtrlSetState($Button2, $GUI_ENABLE)
            InetGet("http://dl_dir.qq.com/qqfile/qq/QQ2009preview4/QQ2009Preview4_chs.exe",@ScriptDir & "\qq.exe", 1, 1)
                Case $Button2
                        if         @InetGetActive Then
                                        $SetDown = 0
                    InetGet("abort")
                    GUICtrlSetState($Button1, $GUI_ENABLE)
                    GUICtrlSetState($Button2, $GUI_DISABLE)
                    GUICtrlSetData($Label1,"未下载")
                    MsgBox(0,"QQ2009 下载器","下载已取消!")
                        EndIf
        EndSwitch
        Sleep(200)
WEnd

Func detect ()
        If @InetGetActive = 0 and $SetDown = 1 Then
                MsgBox(0,"QQ2009 下载器","下载完成!")
                Exit
        EndIf
        If @InetGetActive = 1 and $SetDown = 1 Then
        $baifenbi1 = 18298176 / 100
        $baifenbi = @InetGetBytesRead / $baifenbi1
        GUICtrlSetData($Progress1,$baifenbi)
        GUICtrlSetData($Label1,@InetGetBytesRead/1024 & " KB")
        Else
        GUICtrlSetData($Progress1,0)
        GUICtrlSetData($Label1,"")
        EndIf

EndFunc
发表于 2008-12-19 23:07:59 | 显示全部楼层
http://www.autoitx.com/forum.php?mod=viewthread&tid=4175


看下这个帖子,对你有帮助
 楼主| 发表于 2008-12-20 09:31:21 | 显示全部楼层
搞定,二楼的代码还有些问题
发表于 2008-12-20 12:33:47 | 显示全部楼层
原帖由 78391493 于 2008-12-20 09:31 发表
搞定,二楼的代码还有些问题

有什么问题??
 楼主| 发表于 2008-12-20 16:31:56 | 显示全部楼层

回复 5# auto 的帖子

没下载任何数据就提示下载完成
发表于 2008-12-20 23:55:20 | 显示全部楼层
没有问题啊。。文件下载部他没有修改啊。。还是你写的
既然说不行。。再修改一下
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

$SetDown = 0
Global $size = InetGetSize("http://dl_dir.qq.com/qqfile/qq/QQ2009preview4/QQ2009Preview4_chs.exe")
$Form1 = GUICreate("QQ2009 下载器", 330, 74)
$Progress1 = GUICtrlCreateProgress(8, 8, 313, 25)
$Button1 = GUICtrlCreateButton("开始下载", 88, 40, 113, 25, $BS_DEFPUSHBUTTON)
$Button2 = GUICtrlCreateButton("取消下载", 208, 40, 113, 25, 0)
GUICtrlSetState(-1, $GUI_DISABLE)
$Label1 = GUICtrlCreateLabel("未下载", 8, 48, 72, 17)
GUISetState(@SW_SHOW)
AdlibEnable("detect",500)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
                        $SetDown = 1
            GUICtrlSetState($Button1, $GUI_DISABLE)
            GUICtrlSetState($Button2, $GUI_ENABLE)
            InetGet("http://dl_dir.qq.com/qqfile/qq/QQ2009preview4/QQ2009Preview4_chs.exe",@ScriptDir & "\qq.exe", 1, 1)
                Case $Button2
                        if         @InetGetActive Then
                                        $SetDown = 0
                    InetGet("abort")
                    GUICtrlSetState($Button1, $GUI_ENABLE)
                    GUICtrlSetState($Button2, $GUI_DISABLE)
                    GUICtrlSetData($Label1,"未下载")
                    MsgBox(0,"QQ2009 下载器","下载已取消!")
                        EndIf
        EndSwitch
        Sleep(300)
WEnd

Func detect ()
        If @InetGetActive = 0 and $SetDown = 1 Then
                MsgBox(0,"QQ2009 下载器","下载完成!")
                Sleep(2000)
                Exit
        EndIf
        If @InetGetActive = 1 and $SetDown = 1 Then
        ;$baifenbi1 = $size / 100
        $baifenbi = 100 * @InetGetBytesRead / $size
        GUICtrlSetData($Progress1,$baifenbi)
        GUICtrlSetData($Label1,@InetGetBytesRead/1024 & " KB")
        Else
        GUICtrlSetData($Progress1,0)
        GUICtrlSetData($Label1,"")
        EndIf

EndFunc
 楼主| 发表于 2008-12-21 10:28:16 | 显示全部楼层

回复 7# auto 的帖子

$SetDown = 1应该放在InetGet后面
发表于 2014-5-15 10:01:26 | 显示全部楼层
雷锋精神传天下!谢谢分享!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-28 02:01 , Processed in 0.079325 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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