找回密码
 加入
搜索
查看: 5372|回复: 11

[网络通信] [已解决]如何通过点击X关闭循环中的脚本

  [复制链接]
发表于 2014-3-5 04:07:55 | 显示全部楼层 |阅读模式
本帖最后由 121044246 于 2014-3-6 03:26 编辑

运行程序后进入循环监测IP变动导致无法点击右上角的X关闭程序,只能通过右下角托盘图标退出或者自定义的热键结束程序,请教有什么办法可以直接点击右上角的关闭结束程序呢?
暗淡$ IP,$ oldip,$ newip
全球$ oMyRet [2]
全球$ 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 [0],“]”)
        如果$ IP [1] <>“”,然后返回$ IP [1]
        返回“0.0.0.0”
ENDFUNC; ==> _GetIP

功能MyErrFunc()
        $ HexNumber =十六进制($ oMyError.number,8)
        $ oMyRet [0] = $ HexNumber
        $ oMyRet [1] = StringStripWS($ oMyError.description,3)
        ConsoleWrite(“###的COM错误号:”&$ HexNumber&“ScriptLine:”&$ oMyError.scriptline&“描述:”&$ oMyRet [1]&@ LF)
        返回SETERROR(1);东西来检查时,该函数返回
ENDFUNC; ==> MyErrFunc

功能_Exit()
        出口
ENDFUNC; ==> _Exit
发表于 2014-3-5 07:53:09 | 显示全部楼层
等待大侠出现。。。
发表于 2014-3-5 09:24:34 | 显示全部楼层
需要发送 WM_SYSCOMMAND 消息。

给你代码:
发表于 2014-3-5 09:25:07 | 显示全部楼层
加入以下这段试试
Func WM_SYSCOMMAND($hWnd, $sMsg, $sWParam, $slParam)
        Switch $sWParam
                Case 61536  ;$SC_CLOSE
                        Exit
        EndSwitch
EndFunc
发表于 2014-3-5 12:36:04 | 显示全部楼层
Dim $ip, $oldip, $newip
Global $oMyRet[2]
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[0]], "]")
        If $ip[1] <> "" Then Return $ip[1]
        Return "0.0.0.0"
EndFunc   ;==>_GetIP

Func MyErrFunc()
        $HexNumber = Hex($oMyError.number, 8)
        $oMyRet[0] = $HexNumber
        $oMyRet[1] = StringStripWS($oMyError.description, 3)
        ConsoleWrite("### COM Error !    Number: " & $HexNumber & "    ScriptLine: " & $oMyError.scriptline & "    Description:" & $oMyRet[1] & @LF)
        Return SetError(1); something to check for when this function returns
EndFunc   ;==>MyErrFunc

Func _Exit()
        Exit
EndFunc   ;==>_Exit
发表于 2014-3-5 12:41:47 | 显示全部楼层
提醒养成好习惯,自己尽量多测试,尽可能的精简无关、多余的代码,能重现问题即可。
太长的代码,很多想帮忙的也会直接略过。
 楼主| 发表于 2014-3-5 15:08:05 | 显示全部楼层
回复 6# afan


    好的谢谢
 楼主| 发表于 2014-3-5 15:08:24 | 显示全部楼层
回复 5# afan


    谢谢,回去试试看
 楼主| 发表于 2014-3-5 15:08:52 | 显示全部楼层
回复 4# 不死帝国


    学习了
 楼主| 发表于 2014-3-5 15:17:35 | 显示全部楼层
回复 6# afan


    对了afan大大,还想请教一个问题,我打算写个跟随系统启动的功能,但是在编辑器运行脚本的话在注册表写入启动项成功了,但是生成exe后,都不成功,rewrite返回值0
发表于 2014-3-5 16:34:38 | 显示全部楼层
回复  afan


    对了afan大大,还想请教一个问题,我打算写个跟随系统启动的功能,但是在编辑器运行脚 ...
121044246 发表于 2014-3-5 15:17



    看看是不是权限问题
 楼主| 发表于 2014-3-5 16:43:13 | 显示全部楼层
回复 11# afan


    已经解决了..不是权限的问题.之前杀毒弹出提示没住点到阻止了..谢谢.
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-6-11 09:51 , Processed in 0.109516 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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