#include "GUIConstantsEx.au3"
#include <GuiStatusBar.au3>
#include <WindowsConstants.au3>
#include <IE.au3>
Opt("GUIOnEventMode", 1)
Opt("TrayOnEventMode", 1)
Opt("TrayMenuMode", 3)
Local $aParts[4] = [330, 470, 530, 100]
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_1 Then
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[0] = 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[0] <> 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[0])
DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $ai_Handle[0])
Else
Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', -1)
EndIf
Return $ai_Return[0]
EndFunc ;==>_ReduceMemory