GUIOnEvent 模式下 循环+倒计时 [已解决]
本帖最后由 zhwu530 于 2012-3-26 15:27 编辑搞不懂 ,用 AdlibRegister 或 Sleep 都没达到要的效果,(也许是自己不会。忘高手指点一下。)#include <GUIConstantsEx.au3>
Opt("GUIOnEventMode", 1)
Global $start = 1 ,$Num=5,$time=10
GUICreate("Parent1")
$OK = GUICtrlCreateButton("OK", 10, 30, 50)
$Cancel = GUICtrlCreateButton("Cancel", 70, -1)
GUICtrlCreateLabel("倒计时", 20, 80, 50, 25)
$Labe1 = GUICtrlCreateLabel("?", 65, 80, 55, 25)
GUICtrlSetFont(-1, 8, 400, 4, "MS Sans Serif")
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlCreateLabel("$i的值为", 200, 80, 80, 25)
$Labe2 = GUICtrlCreateLabel("?", 255, 80, 80, 25)
GUICtrlSetFont(-1, 8, 400, 4, "MS Sans Serif")
GUICtrlSetColor(-1, 0x0000FF)
GUISetState(@SW_SHOW)
GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents")
GUICtrlSetOnEvent($OK, "SpecialEvents")
GUICtrlSetOnEvent($Cancel, "SpecialEvents")
While 1
Sleep(10)
;主循环保留
WEnd
;点击 OK 后开始 OKPressed() 中的循环 ,循环次数 $Num
;循环一次后倒计时开始 , 倒计时时间 $time等待倒计时完了再执行下次循环
;直到循环次数为 $Num或 按了 Cancel 按钮 推出循环。
Func OKPressed()
Local $i = 0
While 1
If $start = 1 Or $Num <> $i Then
GUICtrlSetData($Labe2, $i)
$i += 1
Else
ExitLoop
EndIf
WEnd
EndFunc ;==>OKPressed
Func SpecialEvents()
Switch @GUI_CtrlId
Case $GUI_EVENT_CLOSE
Exit
Case $GUI_EVENT_MINIMIZE
Case $GUI_EVENT_RESTORE
Case $OK
OKPressed()
Case $Cancel
$start = 0
EndSwitch
EndFunc ;==>SpecialEvents
把$Labe2设定一个循环一次的函数
把OKPressed的函数换成判断$Labe2的值为0
再说你这就是个无限循环吗还循环一次 不懂啊,
其实我就是想要达到下图中的功能 就是 循环 和 倒计时 那不知道怎么办了。
窗口代码:#include "GUIConstantsEx.au3"
#include <GuiStatusBar.au3>
#include <WindowsConstants.au3>
#include <IE.au3>
Opt("GUIOnEventMode", 1)
Opt("TrayOnEventMode", 1)
Opt("TrayMenuMode", 3)
Local $aParts =
$GUIMain = GUICreate("Test", 588, 449)
GUICtrlCreateGroup("", 5, 3, 577, 105)
GUICtrlCreateLabel("网址 Http://", 18, 26, 80, 17)
$IEAdd = GUICtrlCreateInput("", 90, 20, 401, 21)
$hStatus = _GUICtrlStatusBar_Create($GUIMain)
_GUICtrlStatusBar_SetParts($hStatus, $aParts)
GUICtrlSetColor(-1, 0xC0C0C0)
GUICtrlCreateLabel("ADSL账号:", 18, 54, 68, 17)
$Adslaccount = GUICtrlCreateInput("", 90, 48, 141, 21)
GUICtrlCreateLabel("密码:", 240, 54, 40, 17)
$Adslpassword = GUICtrlCreateInput("", 280, 48, 121, 21, 0x0020)
$Adsl = GUICtrlCreateLabel("测试...", 410, 52, 35, 25)
GUICtrlSetFont(-1, 8, 400, 4, "MS Sans Serif")
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlSetCursor(-1, 0)
GUICtrlCreateLabel("每间隔", 18, 83, 40, 17)
$TimeSec = GUICtrlCreateInput("10", 55, 79, 30, 18)
GUICtrlCreateLabel("秒, 自动刷新", 88, 83, 75, 17)
$Checkbox1 = GUICtrlCreateCheckbox("每次清除Cookies,", 168, 81, 120, 17)
GUICtrlCreateLabel("刷", 292, 83, 16, 17)
$TimeNum = GUICtrlCreateInput("", 305, 79, 49, 18)
GUICtrlCreateLabel("次停止", 355, 83, 40, 17)
$Began = GUICtrlCreateButton("开始", 450, 55, 51, 45)
$stop = GUICtrlCreateButton("停止", 516, 55, 51, 45)
GUICtrlSetState($stop, $GUI_DISABLE)
GUISetState()
$oIE = _IECreateEmbedded()
GUICtrlCreateObj($oIE, 5, 110, 577, 318)
$EventObject = ObjEvent($oIE, "IEEvent_", "DWebBrowserEvents")
If @error Then Exit MsgBox(0, "错误!", "不可使用COM接口 'DWebBrowserEvents'. 错误代码: " & Hex(@error, 8))
GUISetOnEvent($GUI_EVENT_CLOSE, "gui")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "gui")
GUICtrlSetOnEvent($Adsl, "gui")
GUICtrlSetOnEvent($Began, "gui")
GUICtrlSetOnEvent($stop, "gui")
$item_0 = TrayCreateItem("显示窗口")
TrayCreateItem("")
$item_2 = TrayCreateItem("退 出")
TraySetClick(8)
TraySetOnEvent(-13, "TrayEvent")
TrayItemSetOnEvent($item_2, "ExitScript")
TrayItemSetOnEvent($item_0, "TrayEvent")
While 1
Sleep(100)
WEnd
Func gui()
Switch @GUI_CtrlId
Case $GUI_EVENT_CLOSE
ExitScript()
Case $GUI_EVENT_MINIMIZE
GUISetState(@SW_HIDE)
Case $Began
Case $stop
Case $Adsl
EndSwitch
EndFunc ;==>gui
Func TrayEvent()
Switch @TRAY_ID
Case -13, $item_0
GUISetState(@SW_SHOW, $GUIMain)
GUISetState(@SW_RESTORE, $GUIMain)
EndSwitch
EndFunc ;==>TrayEvent
Func ExitScript()
$EventObject.Stop ; 不再接收事件
$EventObject = 0 ; 关闭Event Object
$oIE = 0 ; 清除内存
GUIDelete()
Exit
EndFunc 谁帮我弄下? 论坛里有例子 就是 循环 和 倒计时
我也碰到相似的问题,最后倒计时只好不用了 回复 3# zhwu530
循环倒计时刷新,就是不能点cancel退出,只有等待循环结束,不知道咋整,下面代码供参考
#include <GUIConstantsEx.au3>
Opt("GUIOnEventMode", 1)
Global $start = 1 ,$Num=5,$time=10
GUICreate("Parent1")
GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents")
$OK = GUICtrlCreateButton("OK", 10, 30, 50)
GUICtrlSetOnEvent($OK, "SpecialEvents")
$Cancel = GUICtrlCreateButton("Cancel", 70, -1)
GUICtrlSetOnEvent($Cancel, "SpecialEvents")
GUICtrlCreateLabel("倒计时", 20, 80, 50, 25)
$Labe1 = GUICtrlCreateLabel("?", 65, 80, 55, 25)
GUICtrlSetFont(-1, 8, 400, 4, "MS Sans Serif")
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlCreateLabel("$i的值为", 200, 80, 80, 25)
$Labe2 = GUICtrlCreateLabel("?", 255, 80, 80, 25)
GUICtrlSetFont(-1, 8, 400, 4, "MS Sans Serif")
GUICtrlSetColor(-1, 0x0000FF)
GUISetState(@SW_SHOW)
Local $i = 0
While 1
Sleep(10)
;主循环保留
WEnd
;点击 OK 后开始 OKPressed() 中的循环 ,循环次数 $Num
;循环一次后倒计时开始 , 倒计时时间 $time等待倒计时完了再执行下次循环
;直到循环次数为 $Num或 按了 Cancel 按钮 推出循环。
Func OKPressed($Refresh_internal, $Refresh_Count) ;刷新时间间隔和刷新次数
Local $i=1 ,$Time_0,$Time_1,$Time_2,$time_3,$istart
Local $count = $Refresh_internal
MsgBox(0,"刷新","第"& $i&"次")
For $i = 2 To $Refresh_Count
$Time_0 = @SEC
$Time_2 = @SEC
While 1
$Time_1 = @SEC
$Time_3 = @SEC
GUICtrlSetData($Labe1,$Count)
If $time_3 <> $Time_2 Then ;倒计时
$count -= 1
GUICtrlSetData($Labe1,$count)
$time_2 = $Time_3
EndIf
If $Time_1 < $Time_0 Then $Time_1 = $Time_1 + 60
If $Time_1 - $Time_0 = $Refresh_internalThen;刷新间隔时间到
MsgBox(0,"刷新","第"& $i&"次")
$count = $Refresh_internal
GUICtrlSetData($Labe1,$count)
ExitLoop
EndIf
Sleep(100)
WEnd
Next
MsgBox(0,"刷新","已经刷新了"& $i-1 &"次,结束刷新!")
EndFunc ;==>OKPressed
Func SpecialEvents()
Switch @GUI_CtrlId
Case $GUI_EVENT_CLOSE
Exit
Case $GUI_EVENT_MINIMIZE
Case $GUI_EVENT_RESTORE
Case $OK
OKPressed(10,5)
Case $Cancel
$start = 0
EndSwitch
EndFunc ;==>SpecialEvents 本帖最后由 lixiaolong 于 2012-3-24 23:56 编辑
回复 1# zhwu530
不知道对不对.
#include <GUIConstantsEx.au3>
Opt("GUIOnEventMode", 1)
Global $start = 1, $Num = 5, $time = 10
GUICreate("Parent1")
$OK = GUICtrlCreateButton("OK", 10, 30, 50)
$Cancel = GUICtrlCreateButton("Cancel", 70, -1)
GUICtrlCreateLabel("倒计时", 20, 80, 50, 25)
$Labe1 = GUICtrlCreateLabel("?", 65, 80, 55, 25)
GUICtrlSetFont(-1, 8, 400, 4, "MS Sans Serif")
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlCreateLabel("$i的值为", 200, 80, 80, 25)
$Labe2 = GUICtrlCreateLabel("?", 255, 80, 80, 25)
GUICtrlSetFont(-1, 8, 400, 4, "MS Sans Serif")
GUICtrlSetColor(-1, 0x0000FF)
GUISetState(@SW_SHOW)
GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents")
GUICtrlSetOnEvent($OK, "SpecialEvents")
;~ GUICtrlSetOnEvent($Cancel, "SpecialEvents")
While 1
Sleep(10)
;主循环保留
WEnd
;点击 OK 后开始 OKPressed() 中的循环 ,循环次数 $Num
;循环一次后倒计时开始 , 倒计时时间 $time等待倒计时完了再执行下次循环
;直到循环次数为 $Num或 按了 Cancel 按钮 推出循环。
Func OKPressed()
Opt("GUIOnEventMode", 0)
Local $i = 1, $s = $time
While $start = 1
$nMsg = GUIGetMsg()
If $nMsg = -3 Then Exit
If $nMsg = $Cancel Then $start = 0
If $Num >= $i Then
GUICtrlSetData($Labe2, $i)
$i += 1
While 1
$nMsg = GUIGetMsg()
If $nMsg = -3 Then Exit
If $nMsg = $Cancel Or $i > $Num Then
ExitLoop 2
EndIf
If $s = 0 Then
$s = $time
ExitLoop
EndIf
$s -= 1
GUICtrlSetData($Labe1, $s)
$begin = TimerInit()
While TimerDiff($begin) <= 1000; Sleep 1秒,因为用Sleep无法停止,所以用TimerDiff来代替Sleep.
$nMsg = GUIGetMsg();使用两次GUIGetMsg()会反应迟钝.
If $nMsg = -3 Then Exit
If $nMsg = $Cancel Then
ExitLoop 3
EndIf
WEnd
WEnd
EndIf
WEnd
$start = 1
Opt("GUIOnEventMode", 1)
EndFunc ;==>OKPressed
Func SpecialEvents()
Switch @GUI_CtrlId
Case $GUI_EVENT_CLOSE
Exit
Case $GUI_EVENT_MINIMIZE
Case $GUI_EVENT_RESTORE
Case $OK
OKPressed()
;~ Case $Cancel
;~ $start = 0
EndSwitch
EndFunc ;==>SpecialEvents
不知道还有其他方案解决这个问题的没。 不知道还有其他方案解决这个问题的没。
zhwu530 发表于 2012-3-25 08:54 http://www.autoitx.com/images/common/back.gif
试下 AdlibRegister 函数?#include <GUIConstantsEx.au3>
Opt("GUIOnEventMode", 1)
Global $start, $Num, $time
GUICreate("Parent1")
$OK = GUICtrlCreateButton("OK", 10, 30, 50)
$Cancel = GUICtrlCreateButton("Cancel", 70, -1)
GUICtrlCreateLabel("倒计读秒: ", 20, 80, 70, 25)
$Labe1 = GUICtrlCreateLabel("?", 75, 80, 55, 25)
GUICtrlSetFont(-1, 8, 400, 4, "MS Sans Serif")
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlCreateLabel("倒计轮数: ", 200, 80, 80, 25)
$Labe2 = GUICtrlCreateLabel("?", 255, 80, 80, 25)
GUICtrlSetFont(-1, 8, 400, 4, "MS Sans Serif")
GUICtrlSetColor(-1, 0x0000FF)
GUISetState(@SW_SHOW)
GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents")
GUICtrlSetOnEvent($OK, "SpecialEvents")
GUICtrlSetOnEvent($Cancel, "SpecialEvents")
While 1
If $start And $time < 1 Then _Do_Something() ; 倒计时完成一次, 执行任务函数...
Sleep(10)
;主循环保留
WEnd
;点击 OK 后开始 CountDown() 中的循环 ,循环次数 $Num
;循环一次后倒计时开始 , 倒计时时间 $time等待倒计时完了再执行下次循环
;直到循环次数为 $Num或 按了 Cancel 按钮 推出循环。
Func CountDown()
If $Num < 0 Then $start = False
If $start Then
GUICtrlSetData($Labe2, $Num)
If $time < 0 Then
$Num -= 1
$time = 10
EndIf
GUICtrlSetData($Labe1, $time)
$time -= 1
Else
AdlibUnRegister('CountDown')
GUICtrlSetData($Labe1, 'Finished')
GUICtrlSetData($Labe2, 'Finished')
EndIf
EndFunc ;==>CountDown
Func SpecialEvents()
Switch @GUI_CtrlId
Case $GUI_EVENT_CLOSE
Exit
Case $GUI_EVENT_MINIMIZE
Case $GUI_EVENT_RESTORE
Case $OK
If $time < 1 Or Not $start Then
$Num = 5
$start = True
$time = 10
EndIf
AdlibRegister('CountDown', 1000)
Case $Cancel
$start = False
AdlibUnRegister('CountDown')
GUICtrlSetData($Labe1, 'Cancel')
GUICtrlSetData($Labe2, 'Cancel')
EndSwitch
EndFunc ;==>SpecialEvents
Func _Do_Something()
; execute codes after each countdown.
EndFunc $Labe2 中是显示循环的次数 ,不是倒计次数#include <GUIConstantsEx.au3>
Opt("GUIOnEventMode", 1)
Global $start, $Num, $time
GUICreate("Parent1")
$OK = GUICtrlCreateButton("OK", 10, 30, 50)
$Cancel = GUICtrlCreateButton("Cancel", 70, -1)
GUICtrlCreateLabel("倒计读秒: ", 20, 80, 70, 25)
$Labe1 = GUICtrlCreateLabel("?", 75, 80, 55, 25)
GUICtrlSetFont(-1, 8, 400, 4, "MS Sans Serif")
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlCreateLabel("轮数: ", 200, 80, 80, 25) ; 循环的次数
$Labe2 = GUICtrlCreateLabel("?", 255, 80, 80, 25)
GUICtrlSetFont(-1, 8, 400, 4, "MS Sans Serif")
GUICtrlSetColor(-1, 0x0000FF)
GUISetState(@SW_SHOW)
GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents")
GUICtrlSetOnEvent($OK, "SpecialEvents")
GUICtrlSetOnEvent($Cancel, "SpecialEvents")
While 1
If $start And $time < 1 Then _Do_Something() ; 倒计时完成一次, 执行任务函数...
Sleep(10)
;主循环保留
WEnd
;点击 OK 后开始 CountDown() 中的循环 ,循环次数 $Num
;循环一次后倒计时开始 , 倒计时时间 $time等待倒计时完了再执行下次循环
;直到循环次数为 $Num或 按了 Cancel 按钮 推出循环。
Func CountDown()
If $Num < 0 Then $start = False
If $start Then
GUICtrlSetData($Labe2, $Num)
If $time < 0 Then
$Num -= 1
$time = 10
EndIf
GUICtrlSetData($Labe1, $time)
$time -= 1
Else
AdlibUnRegister('CountDown')
GUICtrlSetData($Labe1, 'Finished')
GUICtrlSetData($Labe2, 'Finished')
EndIf
EndFunc ;==>CountDown
Func SpecialEvents()
Switch @GUI_CtrlId
Case $GUI_EVENT_CLOSE
Exit
Case $GUI_EVENT_MINIMIZE
Case $GUI_EVENT_RESTORE
Case $OK
If $time < 1 Or Not $start Then
$Num = 5
$start = True
$time = 10
EndIf
AdlibRegister('CountDown', 1000)
Case $Cancel
$start = False
AdlibUnRegister('CountDown')
GUICtrlSetData($Labe1, 'Cancel')
GUICtrlSetData($Labe2, 'Cancel')
EndSwitch
EndFunc ;==>SpecialEvents
Func _Do_Something()
; execute codes after each countdown.
EndFunc $Labe2 中是显示循环的次数 ,不是倒计次数?
那反过来设置初始值: $Num = 1
循环5次: If $Num > 5 then $start = false
后面的: $Num -= 1 改为 $Num += 1
这样不就是了? $Num 可以为空
改动了下,已达到我要的效果,帮看看 还有其他好办法 没。。#include <GUIConstantsEx.au3>
Opt("GUIOnEventMode", 1)
Global $start, $Num, $time, $timeS, $NumS
GUICreate("Parent1")
$OK = GUICtrlCreateButton("OK", 10, 30, 50)
$Cancel = GUICtrlCreateButton("Cancel", 70, -1)
GUICtrlCreateLabel("倒计读秒: ", 20, 80, 70, 25)
$Labe1 = GUICtrlCreateLabel("?", 75, 80, 55, 25)
GUICtrlSetFont(-1, 8, 400, 4, "MS Sans Serif")
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlCreateLabel("轮数: ", 200, 80, 80, 25)
$Labe2 = GUICtrlCreateLabel("?", 255, 80, 80, 25)
GUICtrlSetFont(-1, 8, 400, 4, "MS Sans Serif")
GUICtrlSetColor(-1, 0x0000FF)
GUISetState(@SW_SHOW)
GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents")
GUICtrlSetOnEvent($OK, "SpecialEvents")
GUICtrlSetOnEvent($Cancel, "SpecialEvents")
While 1
If $start And $timeS < 1 Then _Do_Something() ; 倒计时完成一次, 执行任务函数...
Sleep(10)
;主循环保留
WEnd
;点击 OK 后开始 CountDown() 中的循环 ,循环次数 $Num
;循环一次后倒计时开始 , 倒计时时间 $time等待倒计时完了再执行下次循环
;直到循环次数为 $Num或 按了 Cancel 按钮 推出循环。
Func CountDown()
If $NumS = $Num And $Num <> "" Then $start = False
If $start Then
GUICtrlSetData($Labe2, $NumS)
If $timeS < 1 Then
$NumS += 1
$timeS = $time
EndIf
$timeS -= 1
GUICtrlSetData($Labe1, $timeS)
Else
AdlibUnRegister('CountDown')
GUICtrlSetData($Labe1, 'Finished')
GUICtrlSetData($Labe2, 'Finished')
EndIf
EndFunc ;==>CountDown
Func SpecialEvents()
Switch @GUI_CtrlId
Case $GUI_EVENT_CLOSE
Exit
Case $GUI_EVENT_MINIMIZE
Case $GUI_EVENT_RESTORE
Case $OK
If $time < 5Then
$timeS = 5
$time = 5
Else
$timeS = $time
EndIf
$start = True
AdlibRegister('CountDown', 1000)
Case $Cancel
$start = False
AdlibUnRegister('CountDown')
GUICtrlSetData($Labe1, 'Cancel')
GUICtrlSetData($Labe2, 'Cancel')
EndSwitch
EndFunc ;==>SpecialEvents
Func _Do_Something()
MsgBox(0, "", "002")
; execute codes after each countdown.
EndFunc ;==>_Do_Something
$Num 可以为空
改动了下,已达到我要的效果,帮看看 还有其他好办法 没。。
zhwu530 发表于 2012-3-25 16:14 http://www.autoitx.com/images/common/back.gif
没必要弄这么多变量吧?搞得越来越乱了.
3个变量足够了.
1个|(布尔变量),其为假(False)时让自动倒计时函数自动结束运行(结束'自动读秒')
2个(整数变量):
1个用来显示倒计读秒值. 每次读秒时, 它的初始值都为最大秒数, 直至自减为0.
另1个用来显示读秒的轮次, 应该是从1开始, 它则自增至最大轮次. 此后开始新一轮读秒时又应该重置为1. 感谢你的细心教导。
就是为了搞这个东西, 这样的网上有很多。但用别人的怕。所以想自己弄个。
下面是时间 不准。#include "GUIConstantsEx.au3"
#include <GuiStatusBar.au3>
#include <WindowsConstants.au3>
#include <IE.au3>
Opt("GUIOnEventMode", 1)
Opt("TrayOnEventMode", 1)
Opt("TrayMenuMode", 3)
Local $aParts =
Global $DEFAULTINPUTDATA_1 = "如 www.baidu.com 或baidu.com", $Text, $Text2 = ""
Global $MARk_1 = 0, $NONEAACTIVECOLOR = 0xC0C0C0, $start, $TimeS, $Time, $Num, $NumS = 1
Global $hStatus, $Adslaccount, $Adsl, $TimeSec, $TimeNum, $Began, $stop, $oIE, $EventObject, $item_0, $item_2, $IEAdd, $Checkbox1
$GUIMain = GUICreate("Test", 588, 449)
GUICtrlCreateGroup("", 5, 3, 577, 105)
GUICtrlCreateLabel("网址 Http://", 18, 26, 80, 17)
$IEAdd = GUICtrlCreateInput($DEFAULTINPUTDATA_1, 90, 20, 401, 21)
$hStatus = _GUICtrlStatusBar_Create($GUIMain)
_GUICtrlStatusBar_SetParts($hStatus, $aParts)
GUICtrlSetColor(-1, 0xC0C0C0)
$OpenIE = GUICtrlCreateButton("打开", 500, 18, 70, 25)
GUICtrlCreateLabel("ADSL账号:", 18, 54, 68, 17)
$Adslaccount = GUICtrlCreateInput("", 90, 48, 141, 21)
GUICtrlCreateLabel("密码:", 240, 54, 40, 17)
$Adslpassword = GUICtrlCreateInput("", 280, 48, 121, 21, 0x0020)
$Adsl = GUICtrlCreateLabel("测试...", 410, 52, 35, 25)
GUICtrlSetFont(-1, 8, 400, 4, "MS Sans Serif")
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlSetCursor(-1, 0)
GUICtrlCreateLabel("每间隔", 18, 83, 40, 17)
$TimeSec = GUICtrlCreateInput("10", 55, 79, 30, 18)
GUICtrlCreateLabel("秒, 自动刷新", 88, 83, 75, 17)
$Checkbox1 = GUICtrlCreateCheckbox("每次清除Cookies,", 168, 81, 120, 17)
GUICtrlCreateLabel("刷", 292, 83, 16, 17)
$TimeNum = GUICtrlCreateInput("", 305, 79, 49, 18)
GUICtrlCreateLabel("次停止", 355, 83, 40, 17)
$Began = GUICtrlCreateButton("开始", 450, 55, 51, 45)
$stop = GUICtrlCreateButton("停止", 516, 55, 51, 45)
GUICtrlSetState($stop, $GUI_DISABLE)
GUISetState()
$oIE = _IECreateEmbedded()
GUICtrlCreateObj($oIE, 5, 110, 577, 318)
$EventObject = ObjEvent($oIE, "IEEvent_", "DWebBrowserEvents")
If @error Then Exit MsgBox(0, "错误!", "不可使用COM接口 'DWebBrowserEvents'. 错误代码: " & Hex(@error, 8))
GUISetOnEvent($GUI_EVENT_CLOSE, "gui")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "gui")
GUICtrlSetOnEvent($Adsl, "gui")
GUICtrlSetOnEvent($Began, "gui")
GUICtrlSetOnEvent($stop, "gui")
$item_0 = TrayCreateItem("显示窗口")
TrayCreateItem("")
$item_2 = TrayCreateItem("退 出")
TraySetClick(8)
TraySetOnEvent(-13, "TrayEvent")
TrayItemSetOnEvent($item_2, "ExitScript")
TrayItemSetOnEvent($item_0, "TrayEvent")
While 1
_CheckInput($GUIMain, $IEAdd, "如 www.baidu.com 或baidu.com", $DEFAULTINPUTDATA_1, $MARk_1)
If GUICtrlRead($IEAdd) = "" Or GUICtrlRead($IEAdd) = $DEFAULTINPUTDATA_1Then
If BitAND(GUICtrlGetState($Began), $gui_enable) Then
GUICtrlSetState($Began, $GUI_DISABLE)
EndIf
Else
If BitAND(GUICtrlGetState($Began), $GUI_DISABLE) And $start = False Then
GUICtrlSetState($Began, $gui_enable)
EndIf
EndIf
If GUICtrlRead($TimeNum) <> "" And GUICtrlRead($TimeNum) < 1 And Not IsNumber(GUICtrlRead($TimeNum)) Then
MsgBox(0, "", "只能为空或是大于零的整数")
GUICtrlSetData($TimeNum, "")
EndIf
If $start And $TimeS < 1 Then ActiveFlow()
_ReduceMemory()
Sleep(100)
WEnd
Func gui()
Switch @GUI_CtrlId
Case $GUI_EVENT_CLOSE
ExitScript()
Case $GUI_EVENT_MINIMIZE
GUISetState(@SW_HIDE)
Case $Began
GUICtrlSetState($IEAdd, $GUI_DISABLE)
GUICtrlSetState($Began, $GUI_DISABLE)
GUICtrlSetState($stop, $gui_enable)
If GUICtrlRead($TimeSec) < 5 Then
$TimeS = 5
$Time = 5
Else
$TimeS = GUICtrlRead($TimeSec)
$Time =GUICtrlRead($TimeSec)
EndIf
$start = True
$Num= GUICtrlRead($TimeNum)
ActiveFlow()
AdlibRegister('CountDown', 1000)
Case $stop
$start = False
AdlibUnRegister('CountDown')
_GUICtrlStatusBar_SetText($hStatus, "已停止", 2)
GUICtrlSetState($stop, $GUI_DISABLE)
GUICtrlSetState($Began, $gui_enable)
GUICtrlSetState($IEAdd, $gui_enable)
Case $Adsl
If GUICtrlRead($Adslaccount) And GUICtrlRead($Adslaccount) <> "" Then
RunWait(@ComSpec & " /c rasdial 宽带连接 /disconnect", "", 0)
RunWait(@ComSpec & " /c rasdial 宽带连接 " & GUICtrlRead($Adslaccount) & " " & GUICtrlRead($Adslpassword), "", @SW_HIDE)
$x = DllCall("sensapi.dll", "int", "IsNetworkAlive", "str", 0x1)
If $x = 1 Then
MsgBox(0, "", "连接成功")
Else
MsgBox(0, "", "宽带连接错误,请检查网络确认宽带账号和密码是否正确")
EndIf
EndIf
EndSwitch
EndFunc ;==>gui
Func TrayEvent()
Switch @TRAY_ID
Case -13, $item_0
GUISetState(@SW_SHOW, $GUIMain)
GUISetState(@SW_RESTORE, $GUIMain)
EndSwitch
EndFunc ;==>TrayEvent
Func CountDown()
If $NumS > $Num And $Num <> "" Then $start = False
If $start Then
_GUICtrlStatusBar_SetText($hStatus, $NumS, 3)
If $TimeS < 1 Then
$NumS += 1
$TimeS = $Time
EndIf
$TimeS -= 1
_GUICtrlStatusBar_SetText($hStatus, $TimeS, 2)
Else
AdlibUnRegister('CountDown')
_GUICtrlStatusBar_SetText($hStatus, "完成", 2)
EndIf
EndFunc ;==>CountDown
Func ExitScript()
$EventObject.Stop ; 不再接收事件
$EventObject = 0 ; 关闭Event Object
$oIE = 0 ; 清除内存
GUIDelete()
Exit
EndFunc ;==>ExitScript
Func IEEvent_StatusTextChange($Text)
If $Text <> '' And StringLeft($Text, 4) = "http" Then $Text2 = $Text
_GUICtrlStatusBar_SetText($hStatus, $Text)
EndFunc ;==>IEEvent_StatusTextChange
Func ActiveFlow()
Local $x
$x = DllCall("sensapi.dll", "int", "IsNetworkAlive", "str", 0x1)
If $x <> 1 Then
MsgBox(0, "", "网络连接失败请检查网络!")
EndIf
$oIE.Navigate("http://" & GUICtrlRead($IEAdd))
Sleep(1000)
GUISwitch($GUIMain)
_GUICtrlStatusBar_SetText($hStatus, _GetInternetIP(), 1)
If GUICtrlRead($Adslaccount) And GUICtrlRead($Adslaccount) <> "" Then
RunWait(@ComSpec & " /c rasdial 宽带连接 /disconnect", "", 0)
RunWait(@ComSpec & " /c rasdial 宽带连接 " & GUICtrlRead($Adslaccount) & " " & GUICtrlRead($Adslpassword), "", @SW_HIDE)
EndIf
EndFunc ;==>ActiveFlow
Func _CheckInput($hWnd, $ID, $InputDefText, ByRef $DefaultInputData, ByRef $Mark)
If $Mark = 0 And _IsFocused($hWnd, $ID) And $DefaultInputData = $InputDefText Then
$Mark = 1
GUICtrlSetData($ID, "")
GUICtrlSetColor($ID, 0x000000)
$DefaultInputData = ""
ElseIf $Mark = 1 And Not _IsFocused($hWnd, $ID) And $DefaultInputData = "" And GUICtrlRead($ID) = "" Then
$Mark = 0
$DefaultInputData = $InputDefText
GUICtrlSetData($ID, $DefaultInputData)
GUICtrlSetColor($ID, $NONEAACTIVECOLOR)
EndIf
EndFunc ;==>_CheckInput
Func _IsFocused($hWnd, $nCID)
Return ControlGetHandle($hWnd, '', $nCID) = ControlGetHandle($hWnd, '', ControlGetFocus($hWnd))
EndFunc ;==>_IsFocused
Func _GetInternetIP()
Local $ip
$ip = InetRead("http://www.aamailsoft.com/getip.php", 1)
$ip = BinaryToString($ip)
If StringStripWS($ip, 8) <> "" Then
Return $ip
Else
Return "0.0.0.0"
EndIf
EndFunc ;==>_GetInternetIP
Func _ReduceMemory()
Local $i_PID = @AutoItPID
If $i_PID <> -1 Then
Local $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $i_PID)
Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $ai_Handle)
DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $ai_Handle)
Else
Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', -1)
EndIf
Return $ai_Return
EndFunc ;==>_ReduceMemory
如果是你要写个和我这个功能一样的。你会怎么来写呢。方便弄一个吗。 感谢你的细心教导。
就是为了搞这个东西, 这样的网上有很多。但用别人的怕。所以想自己弄个。
下面 ...
zhwu530 发表于 2012-3-25 17:18 http://www.autoitx.com/images/common/back.gif
自己用的东西? 我一般不搞倒计时之类的没用的东西.
会只放上核心功能!
自己稍稍用点心吧.
如果你完全理解透它每个函数的功用, 会很容易改成自己的所用的(换上自己的代码)
页:
[1]
2