[已解决]如何通过点击X关闭循环中的脚本
本帖最后由 121044246 于 2014-3-6 03:26 编辑运行程序后进入循环监测IP变动导致无法点击右上角的X关闭程序,只能通过右下角托盘图标退出或者自定义的热键结束程序,请教有什么办法可以直接点击右上角的关闭结束程序呢?暗淡$ IP,$ oldip,$ newip
全球$ oMyRet
全球$ oMyError = ObjEvent(“AutoIt.Error”,“MyErrFunc”)
全球$暂停
HotKeySet(“{暂停}”,“_Exit”)
$ oldip = _GetIP()
$ Form1中= GUICreate(“李少君”,183,86,370,198)
$复选框= GUICtrlCreateCheckbox(“自动发送的IP到电子邮件”,5,35,153,25)
GUICtrlSetFont(-1,12,400,0,“微软雅黑”)
$ SETIP = GUICtrlCreateLabel($ oldip,5,8,172,20)
GUICtrlSetFont(-1,17,800,0,“微软雅黑”)
GUICtrlSetColor(-1,而0x00FF00)
$时间= GUICtrlCreateLabel(“”,5,70,172,20)
GUICtrlSetFont(-1,10,800,0,“微软雅黑”)
GUICtrlSetColor(-1,0x456FFF)
GUISetState(@ SW_SHOW)
全球ITIME $ 10 =
AdlibRegister('__Timer',1000)
虽然1
$ Nmsg个= GUIGetMsg()
开关$ Nmsg个
案例-3
_exit()
案例$ SETIP
MSGBOX(0,“”,参考GUICtrlRead($ SETIP))
EndSwitch
WEND
功能__定时器()
GUICtrlSetData($时间,“距离下次刷新时间还有”&$ ITIME&“秒”)
$ ITIME-= 1
如果$ ITIME> = 0则返回
$ ITIME = 10
$ newip = _GetIP()
GUICtrlSetData($ SETIP,$ newip)
如果参考GUICtrlRead($复选框)= 1,则
如果$ oldip <> $ newip和$ oldip <>“0.0.0.0”那MSGBOX(64,'OK','进入发送电子邮件函数')
其他
如果$ oldip <> $ newip和$ oldip <>“0.0.0.0”那
$选择位= MSGBOX(65,“温馨提醒”,“当前的IP已变更,是否发送电子邮件”,3)
如果$选择位= 1然后MSGBOX(64,'OK','进入发送电子邮件函数')
ENDIF
ENDIF
ENDFUNC; ==> __Timer
功能_GetIP()
$ IP = InetRead(“http://iframe.ip138.com/ic.asp”,1)
$ IP = BinaryToString($ IP,8)
$ IP = StringStripCR($ IP)
$ IP = StringSplit($ ip的,“[”)
$ IP = StringSplit($ IP [$ IP ,“]”)
如果$ IP <>“”,然后返回$ IP
返回“0.0.0.0”
ENDFUNC; ==> _GetIP
功能MyErrFunc()
$ HexNumber =十六进制($ oMyError.number,8)
$ oMyRet = $ HexNumber
$ oMyRet = StringStripWS($ oMyError.description,3)
ConsoleWrite(“###的COM错误号:”&$ HexNumber&“ScriptLine:”&$ oMyError.scriptline&“描述:”&$ oMyRet &@ LF)
返回SETERROR(1);东西来检查时,该函数返回
ENDFUNC; ==> MyErrFunc
功能_Exit()
出口
ENDFUNC; ==> _Exit
等待大侠出现。。。 需要发送 WM_SYSCOMMAND 消息。
给你代码: 加入以下这段试试
Func WM_SYSCOMMAND($hWnd, $sMsg, $sWParam, $slParam)
Switch $sWParam
Case 61536;$SC_CLOSE
Exit
EndSwitch
EndFunc
Dim $ip, $oldip, $newip
Global $oMyRet
Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
Global $Paused
HotKeySet("{PAUSE}", "_Exit")
$oldip = _GetIP()
$Form1 = GUICreate("Joanna Lee", 183, 86, 370, 198)
$Checkbox = GUICtrlCreateCheckbox("自动发送 IP 到Email", 5, 35, 153, 25)
GUICtrlSetFont(-1, 12, 400, 0, "微软雅黑")
$setip = GUICtrlCreateLabel($oldip, 5, 8, 172, 20)
GUICtrlSetFont(-1, 17, 800, 0, "微软雅黑")
GUICtrlSetColor(-1, 0x00FF00)
$time = GUICtrlCreateLabel("", 5, 70, 172, 20)
GUICtrlSetFont(-1, 10, 800, 0, "微软雅黑")
GUICtrlSetColor(-1, 0x456FFF)
GUISetState(@SW_SHOW)
Global $Itime = 10
AdlibRegister('__Timer', 1000)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case -3
_Exit()
Case $setip
MsgBox(0, "", GUICtrlRead($setip))
EndSwitch
WEnd
Func __Timer()
GUICtrlSetData($time, "距离下次刷新时间还有" & $Itime & "秒")
$Itime -= 1
If $Itime >= 0 Then Return
$Itime = 10
$newip = _GetIP()
GUICtrlSetData($setip, $newip)
If GUICtrlRead($Checkbox) = 1 Then
If $oldip <> $newip And $oldip <> "0.0.0.0" Then MsgBox(64, 'ok', '进入发送Email函数')
Else
If $oldip <> $newip And $oldip <> "0.0.0.0" Then
$selec = MsgBox(65, "温馨提醒", "当前IP已变更,是否发送Email", 3)
If $selec = 1 Then MsgBox(64, 'ok', '进入发送Email函数')
EndIf
EndIf
EndFunc ;==>__Timer
Func _GetIP()
$ip = InetRead("http://iframe.ip138.com/ic.asp", 1)
$ip = BinaryToString($ip, 8)
$ip = StringStripCR($ip)
$ip = StringSplit($ip, "[")
$ip = StringSplit($ip[$ip], "]")
If $ip <> "" Then Return $ip
Return "0.0.0.0"
EndFunc ;==>_GetIP
Func MyErrFunc()
$HexNumber = Hex($oMyError.number, 8)
$oMyRet = $HexNumber
$oMyRet = StringStripWS($oMyError.description, 3)
ConsoleWrite("### COM Error ! Number: " & $HexNumber & " ScriptLine: " & $oMyError.scriptline & " Description:" & $oMyRet & @LF)
Return SetError(1); something to check for when this function returns
EndFunc ;==>MyErrFunc
Func _Exit()
Exit
EndFunc ;==>_Exit
提醒养成好习惯,自己尽量多测试,尽可能的精简无关、多余的代码,能重现问题即可。
太长的代码,很多想帮忙的也会直接略过。 回复 6# afan
好的谢谢 回复 5# afan
谢谢,回去试试看 回复 4# 不死帝国
学习了 回复 6# afan
对了afan大大,还想请教一个问题,我打算写个跟随系统启动的功能,但是在编辑器运行脚本的话在注册表写入启动项成功了,但是生成exe后,都不成功,rewrite返回值0 回复afan
对了afan大大,还想请教一个问题,我打算写个跟随系统启动的功能,但是在编辑器运行脚 ...
121044246 发表于 2014-3-5 15:17 http://www.autoitx.com/images/common/back.gif
看看是不是权限问题 回复 11# afan
已经解决了..不是权限的问题.之前杀毒弹出提示没住点到阻止了..谢谢.
页:
[1]