循环再套循环 然后判断按钮的问题
#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 编辑 ] #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 http://www.autoitx.com/forum.php?mod=viewthread&tid=4175
看下这个帖子,对你有帮助 搞定,二楼的代码还有些问题 原帖由 78391493 于 2008-12-20 09:31 发表 http://www.autoitx.com/images/common/back.gif
搞定,二楼的代码还有些问题
有什么问题??
回复 5# auto 的帖子
没下载任何数据就提示下载完成 没有问题啊。。文件下载部他没有修改啊。。还是你写的既然说不行。。再修改一下
#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
回复 7# auto 的帖子
$SetDown = 1应该放在InetGet后面 雷锋精神传天下!谢谢分享!
页:
[1]